Releases: haltcase/trilogy
v2.0.5
v2.0.4
v2.0.3
v2.0.2
v2.0.1
v2.0.0
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:
- rewritten in TypeScript
- lifecycle hooks
- Node 8.10 minimum version requirement
To try it out, use:
# using yarn
yarn add trilogy
# using npm
npm i trilogyThe documentation has also been expanded and improved, and is available at
https://trilogy.js.org.
codename: solid source
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:
click to expand
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'?
})()lifecycle hooks
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.
click to expand
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()
})()BUG FIXES
- store dates as ISO formatted strings (d2a7cda)
FEATURES
- write trilogy in typescript
- add lifecycle hooks
- remove
verbosein favor ofonQueryhook (cf7d085) - invariant: throw standard
Errorinstead of custom type (5a4bf70) - schema: make
nullableactually work inversely tonotNullable(e4ccc51) - schema-helpers: throw on non-string column types (43eebb6)
- where,cast: make casting & where clauses stricter (3ecee37)
- schema-helpers: throw on empty schemas (ce4a066)
- throw if property name is required but not provided (ede6363)
- find*: move column signatures into their own methods (a73f773)
- count: split
model.countwith column tocountIn(df4ccb4) - schema-helpers: throw on invalid column types (9d22fc2)
- enforce valid option parameters with
runtypes(755555d) - unabbreviate
incr&decrmethods (04404fe) - upgrade to sql.js 1.x (9669dcf)
PERFORMANCE
- count: avoid
argumentsusage (cb33ff1)
BREAKING CHANGES
- schema: providing both the
nullable¬Nullableproperties will cause anErrorto be thrown. - where,cast: invalid where clauses and unrecognized types at casting will now cause
Errors to be thrown. - schema-helpers: an error will be thrown when column type cannot be retrieved.
- invariant:
InvariantErrors are no longer thrown, they areErrors instead. - flow: flow definitions have been removed.
- find*:
find()andfindOne()on models no longer accept an optional column argument. Instead, use the newfindIn()orfindOneIn()methods. Top level trilogy methods still accepttable.columndot notation. - count:
model.countno longer has a signature allowing a column as the first parameter. This is now a separate method calledcountIn. - schema-helpers: using an unknown column type in a descriptor will now result in an error.
- an error will now be thrown immediately from methods that require a property name if none is provided.
- date serialization has changed to improve reliability and predictability.
incr&decrhave been renamed toincrement&decrement.- invalid options objects passed to methods accepting them will now cause exceptions to be thrown.
- the
verboseoption has been removed from trilogy instances. Use the newonQueryhook 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:')v2.0.0-rc.5
yarn add trilogy@2.0.0-rc.5v2.0.0-rc.4
yarn add trilogy@2.0.0-rc.4v2.0.0-rc.3
yarn add trilogy@2.0.0-rc3v2.0.0-rc.2
yarn add trilogy@2.0.0-rc.2