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 trilogy
The 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
verbose
in favor ofonQuery
hook (cf7d085) - invariant: throw standard
Error
instead of custom type (5a4bf70) - schema: make
nullable
actually 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.count
with column tocountIn
(df4ccb4) - schema-helpers: throw on invalid column types (9d22fc2)
- enforce valid option parameters with
runtypes
(755555d) - unabbreviate
incr
&decr
methods (04404fe) - upgrade to sql.js 1.x (9669dcf)
PERFORMANCE
- count: avoid
arguments
usage (cb33ff1)
BREAKING CHANGES
- schema: providing both the
nullable
¬Nullable
properties will cause anError
to be thrown. - where,cast: invalid where clauses and unrecognized types at casting will now cause
Error
s to be thrown. - schema-helpers: an error will be thrown when column type cannot be retrieved.
- invariant:
InvariantError
s are no longer thrown, they areError
s 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.column
dot notation. - count:
model.count
no 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
&decr
have been renamed toincrement
&decrement
.- invalid options objects passed to methods accepting them will now cause exceptions to be thrown.
- the
verbose
option has been removed from trilogy instances. Use the newonQuery
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:')
v2.0.0-rc.5
yarn add trilogy@2.0.0-rc.5
v2.0.0-rc.4
yarn add trilogy@2.0.0-rc.4
v2.0.0-rc.3
yarn add trilogy@2.0.0-rc3
v2.0.0-rc.2
yarn add trilogy@2.0.0-rc.2