libero/cli/templates/db

Database-specific templates for libero new --database.

Each function returns file content as a String. These are used only when the –database flag is passed to the scaffold command.

Values

pub fn db_module(database: cli.Database) -> String

Returns server/db.gleam content with connection setup and helpers.

Postgres: a thin wrapper around pog that configures connection pooling. Sqlite: opens the database, sets performance PRAGMAs, and provides a query wrapper that marmot-generated code calls.

pub fn deps(database: cli.Database) -> String

Returns extra dependency lines to insert into the server’s gleam.toml.

Postgres uses pog (a connection pool for PostgreSQL) and squirrel (generates type-safe Gleam code from .sql files).

Sqlite uses sqlight (FFI bindings to SQLite), marmot (generates type-safe Gleam code from .sql files, like squirrel but for SQLite), and logging (so the db module can log queries at debug level).

pub fn extra_toml(database: cli.Database) -> String

Returns extra TOML sections to append after [tools.libero].

Postgres needs nothing here because squirrel reads the database URL from the DATABASE_URL environment variable.

Sqlite needs a [tools.marmot] section that tells marmot where the database file lives and which query function the generated code should call.

pub fn readme_section(database: cli.Database) -> String

Returns a database-specific section to include in the project README.

pub fn shared_state(database: cli.Database) -> String

Returns shared_state.gleam content with a database connection field.

SharedState is created once at server startup and passed into every handler call. Storing the database connection here means handlers don’t need to open their own connections.

Search Document