TypeScript SQLite layer with support for both native C++ & pure JavaScript drivers.
getRaw
(a41da36)v2.0.0 is a significant release, and is the result of a year and a half of work leading up to almost three years since trilogy was first conceived:
The highlights are:
To try it out, use:
# using yarn
yarn add trilogy
# using npm
npm i trilogy
The documentation has also been expanded and improved, and is available at https://trilogy.js.org.
trilogy has been rewritten in TypeScript, which paid off early and often — two of the last three 1.x patch releases contained fixes found in the process of refactoring the code base with types. It also provides a greatly improved editing experience:
import * as trilogy from 'trilogy'
const db = trilogy.connect(':memory:')
// you can provide types like this to `model()`
// to get compiler assistance
type Person = {
name: string
}
;(async () => {
const people = await db.model<Person>('people', {
name: String
})
await people.create({ names: 'typo' })
// !> Property 'names' does not exist in type 'Person'. Did you mean 'name'?
})()
A set of lifecycle hooks has been implemented, of which before*
variants support
canceling events. These hooks are useful for debugging, logging, and simple
plugin-like addons.
import { connect, EventCancellation } from 'trilogy'
const db = connect(':memory:')
;(async () => {
const notRobots = await db.model('notRobots', {
name: String,
intelligence: Number
})
const unsub = notRobots.beforeCreate(async person => {
if (person.intelligence < 1650) {
console.log('ignoring total human- ... uh, robot')
return EventCancellation
}
person.name += ' (totally not a robot)'
})
console.log(await db.create('notRobots', {
name: '0110101101001111010001010',
intelligence: 96156615
}))
// -> { name: '0110101101001111010001010 (totally not a robot)',
// intelligence: 96156615 }
console.log(await db.create('notRobots', {
name: 'Tom',
intelligence: 100
}))
// "ignoring total human- ... uh, robot"
// -> undefined
// removes the hook, objects after this are unaffected
unsub()
await db.close()
})()
verbose
in favor of onQuery
hook (cf7d085)Error
instead of custom type (5a4bf70)nullable
actually work inversely to notNullable
(e4ccc51)model.count
with column to countIn
(df4ccb4)runtypes
(755555d)incr
& decr
methods (04404fe)arguments
usage (cb33ff1)nullable
& notNullable
properties will cause an Error
to be thrown.Error
s to be thrown.InvariantError
s are no longer thrown, they are Error
s instead.find()
and findOne()
on models no longer accept an optional column argument. Instead, use the new findIn()
or findOneIn()
methods. Top level trilogy methods still accept table.column
dot notation.model.count
no longer has a signature allowing a column as the first parameter. This is now a separate method called countIn
.incr
& decr
have been renamed to increment
& decrement
.verbose
option has been removed from trilogy instances. Use the new onQuery
hook instead.Support for Node 4 and Node 6 has been dropped, meaning trilogy now requires >=8.10.
trilogy no longer has a default export in order to better support TypeScript users. The recommended way to create a new instance has also changed (though the old way is still possible).
// before
import Trilogy from 'trilogy'
const db = new Trilogy(':memory:')
// after
import { connect } from 'trilogy'
const db = connect(':memory:')
yarn add [email protected]
yarn add [email protected]
yarn add [email protected]
yarn add [email protected]