Skip to content

Sys.Db

Sys.Db gives server-side code the TypeORM EntityManager of a Server Data Store’s database connection, for queries that the Server Data Store’s own methods cannot express, such as raw SQL or complex query builder statements. For reading and saving Entities, use the Server Data Store methods (This.<StoreName>.…) instead: they apply the store’s access control rules and handle Lowgile’s Entity data correctly.

Availability: Server

const Db: Record<string, EntityManager>

Sys.Db['<moduleId>.<storeName>'] returns the EntityManager of the database connection of that Server Data Store. The key is the store’s qualified name: the Module name and the store name, separated by a dot. Because of the dot, use bracket notation.

The EntityManager is TypeORM’s (version 1.1.1) API for running queries, query builders and transactions on one connection. Lowgile does not wrap it: see the TypeORM EntityManager documentation.

const manager = Sys.Db['MyModule.MyStore']
const [row] = await manager.query('SELECT CURRENT_TIMESTAMP AS now')

Type: EntityManager · Availability: Server

Note

For a name with no open connection, for example a misspelled name or a store whose database is not configured, Sys.Db returns undefined, although the type says EntityManager. Queries through the EntityManager bypass the Server Data Store’s access control rules.