TypeScript SQLite layer with support for both native C++ & pure JavaScript drivers.
yarn add [email protected]
No changes since 1.4.4
- this release restores the v1 release line to the latest
tag, where a v2 beta was accidentally published.
npm i [email protected]
groupBy
-> group
(3eaed9a)Small patch for TypeScript users to correctly export types.
This release brings a pair of exciting features!
First up is the ability to define getters and setters when creating models. These are useful for things like formatting after selects and conforming data before inserts.
const people = await db.model('people', {
name: String,
username: {
type: String,
get (username) {
return `username is: ${username}`
},
set (username) {
// remove anything that isn't alphanumeric or underscore
return username.replace(/[^\w]/gi, '')
}
}
})
await people.create({
name: 'Bo Lingen',
username: 'ci.ty]ci[d/e'
})
// -> { name: 'Bo Lingen', username: 'citycide' }
await people.get('username', { name: 'Bo Lingen' })
// -> 'username is: citycide'
// can use `getRaw()` and `setRaw()` to bypass getters / setters
// other methods may also accept a `raw` property in their options object
await people.getRaw('username', { name: 'Bo Lingen' })
// -> 'citycide'
There's also a new memory-only mode - if the file path is exactly ':memory:', no file will be created and an in-memory store will be used. This doesn't persist any data but is useful for speed and performance reasons. For example, most of trilogy's tests now use in-memory databases to avoid tons of disk usage.
const db = new Trilogy(':memory:')
getRaw()
& setRaw()
(5fe1f80)