db/create_db.ts

Database initialization with driver auto-detection.

Selects the appropriate database driver based on database_url: - postgres:// or postgresql:// — uses pg (PostgreSQL) - file:// — uses @electric-sql/pglite (file-based) - memory:// — uses @electric-sql/pglite (in-memory)

Both pg and @electric-sql/pglite are optional peer dependencies, dynamically imported only when needed. For direct driver construction without auto-detection, use db_pg.ts or db_pglite.ts.

Declarations
#

2 declarations

view source

create_db
#

db/create_db.ts view source

(database_url: string): Promise<CreateDbResult>

Create a database connection based on a URL.

Returns the Db instance, a typed close callback, driver type, and display name. The close callback is bound to the actual driver — callers never need to know which driver is in use.

For direct driver construction without URL routing, import create_pg_db from db_pg.ts or create_pglite_db from db_pglite.ts.

database_url

connection URL (postgres://, postgresql://, file://, or memory://)

type string

returns

Promise<CreateDbResult>

database instance, close callback, type, and display name

CreateDbResult
#

db/create_db.ts view source

CreateDbResult

Result of database initialization.

db

type Db

close

Close the database connection. Bound to the actual driver at construction.

type () => Promise<void>

db_type

type DbType

db_name

type string

Depends on
#

Imported by
#