SqlDatabase
A DataProvider for Sql Databases
example:
const db = new SqlDatabase(new PostgresDataProvider(pgPool))
see:
getDb
Gets the SQL database from the data provider.
returns:
The SQL database.
see:
Arguments:
- dataProvider - The data provider.
createCommand
Creates a new SQL command.
returns:
The SQL command.
see:
execute
Executes a SQL command.
returns:
The SQL result.
see:
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:
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:
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:
const db = new SqlDatabase(new PostgresDataProvider(pgPool))
Arguments:
- sql - The SQL implementation.