Skip to content

SqlDatabase ​

A DataProvider for Sql Databases

example: ​

ts
const db = new SqlDatabase(new PostgresDataProvider(pgPool))

see: ​

Connecting a Database

getDb ​

Gets the SQL database from the data provider.

returns: ​

The SQL database.

see: ​

Direct Database Access

Arguments:

  • dataProvider - The data provider.

createCommand ​

Creates a new SQL command.

returns: ​

The SQL command.

see: ​

Direct Database Access

execute ​

Executes a SQL command.

returns: ​

The SQL result.

see: ​

Direct Database Access

Arguments:

  • sql - The SQL command.

wrapIdentifier ​

Wraps an identifier with the database's identifier syntax.

ensureSchema ​

  • ensureSchema

Arguments:

  • entities

getEntityDataProvider ​

Gets the entity data provider.

returns: ​

The entity data provider.

Arguments:

  • entity - The entity metadata.

transaction ​

Runs a transaction. Used internally by remult when transactions are required

returns: ​

The promise of the transaction.

Arguments:

  • action - The action to run in the transaction.

rawFilter ​

Creates a raw filter for entity filtering.

returns: ​

  • The entity filter with a custom SQL filter.

example: ​

ts
SqlDatabase.rawFilter(({param}) =>
     `"customerId" in (select id from customers where city = ${param(customerCity)})`
   )

see: ​

Leveraging Database Capabilities with Raw SQL in Custom Filters

Arguments:

  • build - The custom SQL filter builder function.

filterToRaw ​

Converts a filter to a raw SQL string.

see: ​

Leveraging Database Capabilities with Raw SQL in Custom Filters

Arguments:

  • repo
  • condition
  • sqlCommand
  • dbNames
  • wrapIdentifier

LogToConsole ​

false (default) - No logging

true - to log all queries to the console

oneLiner - to log all queries to the console as one line

a function - to log all queries to the console as a custom format

example: ​

ts
SqlDatabase.LogToConsole = (duration, query, args) => { console.log("be crazy ;)") }

durationThreshold ​

Threshold in milliseconds for logging queries to the console.

constructor ​

Creates a new SQL database.

example: ​

ts
const db = new SqlDatabase(new PostgresDataProvider(pgPool))

Arguments:

  • sql - The SQL implementation.

end ​

MIT Licensed | Made by the Remult team with ❤️