index
Classes
| Class | Description |
|---|---|
| DbManager | A class which mainly manages "connections" to the sqlite3 database and drizzle ORM. Any package which depends on this will create a single instance given the database schema and config, export the public interface, and be used by queries to access the drizzle ORM. This way the package which depends on @saflib/drizzle has full access to its database, but packages which depend on it only have access to an opaque key which only database queries can use. |
| HandledDatabaseError | A subclass of Error which is used to indicate that an error was caught and handled by the database library. Database packages should subclass this error, and these are not necessarily considered bugs if they occur. |
| UnhandledDatabaseError | A subclass of Error which is used to indicate that an error was not caught and handled by the database library. The cause of the error is not propagated, since consumers of the database libary should not have access to underlying SQL issues. |
Interfaces
| Interface | Description |
|---|---|
| Address | A shared address type that can be used across the platform. |
| DbManagerOptions | Options for constructing a DbManager. |
| DbOptions | When a "connection" is created, these parameters are provided. |
| FileMetadataFields | TypeScript interface for file metadata fields. Use this in your Entity interface when your table includes fileMetadataColumns. Add created_at / updated_at on the entity itself (not via this interface). |
Type Aliases
| Type Alias | Description |
|---|---|
| CreateOnDiskDbKeyAccessorOptions | - |
| DbConnection | The result of calling drizzle, typed to the schema you connected to. |
| DbKey | A symbol returned when connecting to the database. This key should be provided to any queries used by the consumer of the package. This is the only way a database consumer may interact with the database. |
| DbTransaction | Convenience type; the tx object passed to the drizzle transaction callback, with a generic parameter for the schema. |
| Equal | To be used with "Expect" to check explicit table interfaces match Drizzle's inferred interfaces. |
| Expect | To be used with "Equal" to check explicit table interfaces match Drizzle's inferred interfaces. |
| FkCascadeViolation | - |
| Schema | Currently this package expects the schema to be an object where some values are the result of sqliteTable calls. Organize your schema in this fashion when creating your DbManager and such. |
| TransactionCallback | Convenience type; the first parameter of the transaction method, with a generic parameter for the schema. |
Variables
| Variable | Description |
|---|---|
| addressSchema | Drizzle schema for Address type. Use this in your table definitions for address fields. |
| fileMetadataColumns | Common file metadata columns for tables that reference files stored in Azure Blob Storage. Use these columns when your table stores metadata about a file (blob_name, file_original_name, mimetype, size). Timestamps (created_at / updated_at) are not included — declare them on each table so non-file tables and file tables share the same timestamp pattern. |
Functions
| Function | Description |
|---|---|
| assertNoFkCascades | Throw if any migration SQL or schema TS in packageRoot declares FK cascades. Defaults to process.cwd() so package tests can call it with no args. |
| createOnDiskDbKeyAccessor | Lazy singleton for package-owned SQLite files (cron-db, jobs-db, audit-db, …). |
| findFkCascadeViolations | Find FK cascade declarations in a drizzle package. |
| generateShortId | Short random ID (12 base64url chars by default). Uses crypto.getRandomValues; URL-safe. Default byteLength 9 → 72 bits of entropy. Optional byteLength override for callers that need a different width. |
| packageSqlitePath | Absolute SQLite path for a package-owned on-disk DB file. |
| queryWrapper | All queries should use this wrapper. It will catch and obfuscate unhandled errors, and rethrow handled errors, though really handled errors should be returned, not thrown. |