mirror of
https://github.com/hanzoai/orm.git
synced 2026-10-30 15:01:22 +00:00
Wrap an already-open *sql.DB (pragma'd, encrypted at rest, single-writer) as an orm.DB/SQLiteDB instead of opening one from a path. The ORM manages records in a file whose lifecycle the caller owns: one connection serves reads and writes (serialized by writeMu), initSchema ensures _entities, and Close is a no-op so the caller closes the connection it opened. Additive; NewSQLiteDB is unchanged.
22 lines
729 B
Go
22 lines
729 B
Go
package orm
|
|
|
|
import (
|
|
"database/sql"
|
|
|
|
ormdb "github.com/hanzoai/orm/db"
|
|
)
|
|
|
|
// AdaptSQLite layers the ORM over an already-open *sql.DB the CALLER owns, returning
|
|
// the root orm.DB (Get/Put/Query/CreateIfAbsent/RunInTransaction). It is the seam
|
|
// for a store whose SQLite file is opened elsewhere — pragma'd, encrypted at rest,
|
|
// single-writer — and handed in as a *sql.DB: the ORM manages records in the file
|
|
// without owning the file's lifecycle. Close on the returned DB is a no-op; the
|
|
// caller closes the connection it opened. See db.AdaptSQLDB for the full contract.
|
|
func AdaptSQLite(conn *sql.DB) (DB, error) {
|
|
sdb, err := ormdb.AdaptSQLDB(conn)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return AdaptDB(sdb), nil
|
|
}
|