# changelog
# 2.0.5
(opens new window) (2021-08-08)
# BUG FIXES
- ensure timestamps/schema options are handled properly (#112 (opens new window)) (a30b29c (opens new window))
# 2.0.4
(opens new window) (2021-08-08)
# BUG FIXES
- update sql.js type imports (#111 (opens new window)) (3ece338 (opens new window)), closes #109 (opens new window)
# 2.0.3
(opens new window) (2020-06-20)
# BUG FIXES
- types: allow providing value type to
getRaw
(a41da36 (opens new window))
# v2.0.2
(opens new window) (2019-06-30)
# BUG FIXES
- escape input values in raw queries (
43d0558
(opens new window)) - pass descriptor properties to knex properly (
63c9569
(opens new window))
# 2.0.1
(opens new window) (2019-06-24)
# BUG FIXES
- timestamps: only create timestamp triggers when necessary (35dbab6 (opens new window))
# 2.0.0
(opens new window) (2019-06-12)
v2.0.0 is a significant release. The highlights are:
- rewritten in TypeScript
- lifecycle hooks
- Node 8.10 minimum version requirement
To try it out, use:
# using yarn
yarn add trilogy@2.0.0
# using npm
npm i trilogy@2.0.0
The documentation has also been expanded and improved, and is available at https://trilogy.js.org (opens new window).
# 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
const { connect, EventCancellation } = require('./dist')
const db = connect(':memory:')
;(async () => {
const notRobots = await db.model('notRobots', {
name: String,
intelligence: Number
})
const unsub = await 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 (opens new window))
# FEATURES
- write trilogy in typescript
- add lifecycle hooks
- remove
verbose
in favor ofonQuery
hook (cf7d085 (opens new window)) - invariant: throw standard
Error
instead of custom type (5a4bf70 (opens new window)) - schema: make
nullable
actually work inversely tonotNullable
(e4ccc51 (opens new window)) - schema-helpers: throw on non-string column types (43eebb6 (opens new window))
- where,cast: make casting & where clauses stricter (3ecee37 (opens new window))
- schema-helpers: throw on empty schemas (ce4a066 (opens new window))
- throw if property name is required but not provided (ede6363 (opens new window))
- find*: move column signatures into their own methods (a73f773 (opens new window))
- count: split
model.count
with column tocountIn
(df4ccb4 (opens new window)) - schema-helpers: throw on invalid column types (9d22fc2 (opens new window))
- enforce valid option parameters with
runtypes
(755555d (opens new window)) - unabbreviate
incr
&decr
methods (04404fe (opens new window)) - upgrade to sql.js 1.x (9669dcf (opens new window))
# PERFORMANCE
- count: avoid
arguments
usage (cb33ff1 (opens new window))
# 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:')
# v1.4.6
(opens new window) (2019-05-30)
To prevent installation breakage on newer Node releases, a third-party dependency now has its version pinned.
# BUG FIXES
- package: pin osom dependency to prevent installation breakage
# 1.4.5
(opens new window) (2018-04-24)
No changes since 1.4.4
- this release restores the v1 release line to the latest
tag,
where a v2 beta was accidentally publish.
# 1.4.4
(opens new window) (2018-01-09)
# BUG FIXES
- enforcers:
groupBy
->group
(3eaed9a (opens new window))
# 1.4.3
(opens new window) (2018-01-09)
# BUG FIXES
- handle tuple where clauses correctly (efbea74 (opens new window))
# 1.4.2
(opens new window) (2017-12-08)
# BUG FIXES
- create: prevent error while searching for last object (5379bb5 (opens new window))
- types: handle nullish values when casting (e8193c6 (opens new window)), closes #79 (opens new window)
# PERFORMANCE
- util: use
indexOf
instead ofsome()
(559dbe0 (opens new window))
# 1.4.1
(opens new window) (2017-11-16)
Small patch for TypeScript users to correctly export types.
# BUG FIXES
- types: fix TypeScript typings (#75) @IKnowBashFu
# 1.4.0
(opens new window) (2017-11-04)
# FEATURES
- model: allow multiple indices in model definitions, #72 (opens new window) (07ebe16 (opens new window))
# 1.3.0
(opens new window) (2017-08-24)
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 making sure 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:')
# BUG FIXES
- always return promises in async functions (009f079 (opens new window))
# FEATURES
- add support for in-memory database (8587f4b (opens new window))
- add getters & setters (ab5cd7b (opens new window))
- add
getRaw()
&setRaw()
(5fe1f80 (opens new window))
# PERFORMANCE
- model: use assignments in constructor (73e6ebd (opens new window))
- util: optimize
each()
andmap()
(040084d (opens new window))
# 1.2.1
(opens new window) (2017-07-25)
# BUG FIXES
- immediately create db file for both clients (7423312 (opens new window))
- fix
.mjs
module by removingmodule.exports
usage (e1d57c3 (opens new window))
# 1.2.0
(opens new window) (2017-06-09)
# FEATURES
- add initial Flow definitions (b9937b4 (opens new window))
- add initial TypeScript definitions (3d9a2a5 (opens new window))
- support multiple where clauses (ff481bb (opens new window)), closes #54 (opens new window)
# 1.1.0
(opens new window) (2017-03-23)
# BUG FIXES
- findOne: error when no result and column provided (7394150 (opens new window))
# FEATURES
- drop fs-jetpack dependency (4a82ab6 (opens new window))
# 1.0.0
(opens new window) (2017-03-16)
We've officially arrived at 1.0.0!
But don't let that stop you from submitting issues if you come across problems, or pull requests if there's something that can be improved or added.
Thanks for the help getting here!
# BUG FIXES
- incr|decr: do nothing with amounts of 0 (94dd9e0 (opens new window))
# 1.0.0-rc.5
(opens new window) (2017-02-26)
This is probably the last release candidate before 1.0.0!
...
I feel like I've said that before.
# BUG FIXES
- update: handle type definitions on update (eeda08c (opens new window)), closes #31 (opens new window)
# 1.0.0-rc.4
(opens new window) (2017-02-24)
This is probably the last release candidate before 1.0.0!
# BUG FIXES
- native: ensure directory exists (f142cf4 (opens new window))
- package: update fs-jetpack to version 0.11.0 (481a8d6 (opens new window))
- package: update fs-jetpack to version 0.12.0 (3157627 (opens new window))
# 1.0.0-rc.3
(opens new window) (2017-02-04)
This release contains a breaking change regarding the return value of create()
.
You can follow the discussion leading up to this change in
#21 (opens new window),
#22 (opens new window),
& #24 (opens new window).
Many thanks to @jonataswalker (opens new window) who put in a lot of effort for this one.
# BUG FIXES
- create: last object when auto-increment key (6c8acc1 (opens new window))
- create: native vs
sql.js
last object handling (06cfca0 (opens new window)) - model:
sql.js
not returning model on creations (06df94f (opens new window)) - tests.model:
create()
expected return value (baa6ad3 (opens new window))
# FEATURES
- create: return the created object (e551bbd (opens new window))
# PEFORMANCE
- optimize
findLastObject
helper (e90cdff (opens new window))
# BREAKING CHANGES
- create: The return value of
create()
is no longer the number of created objects. Instead,create()
returns the created object.
# 1.0.0-rc.2
(opens new window) (2017-01-17)
# BUG FIXES
- only require
sql.js
if not usingsqlite3
(123149d (opens new window)), closes #18 (opens new window)
# 1.0.0-rc.1
(opens new window) (2017-01-13)
🙌 Welcome to the very first official release candidate of Trilogy! 🙌
The next version will be v1.0.0 unless there are any significant issues discovered.
There have not been significant changes since v0.11.1.
# BUG FIXES
- enforcers: broken descriptor validation (459a485 (opens new window))
# FEATURES
- types: add
Array
andObject
as valid types (421d079 (opens new window))
# 0.11.1
(opens new window) (2017-01-10)
This is a small feature patch on top of v0.11.0 adding model()
options
that include the ability to set compound primary keys, multiple unique
properties, and add timestamp properties (created_at
and updated_at
).
Note: the changes below are mostly from v0.11.0.
# BUG FIXES
- enforcers: verbose option validation (b000a5e (opens new window))
- findOne: sqlite3 response is an object (2f71f5f (opens new window))
- model: argument handling with no column (e76343c (opens new window))
- model: make
model()
async (e3d57f6 (opens new window)) - native: fix affected row return value for native queries (2233a0f (opens new window))
- native: query return types (7519f9e (opens new window))
- query: return type should always be Promise (31cfed7 (opens new window))
models
list type (f77aae5 (opens new window))- model existence check (5591860 (opens new window))
# FEATURES
- add
hasModel()
,dropModel()
, andclose()
(00c0d66 (opens new window)) - add
raw()
method for custom queries (2403e27 (opens new window)) - change
groupBy
usages togroup
(772b252 (opens new window)) - initial commit for rewrite (#14) (26f739f (opens new window))
- clear: add
clear()
method, safeguardremove()
(ab671c1 (opens new window)) - count: add ability to count tables in the database (de9a62d (opens new window))
- create: make
create()
return # rows affected (695753e (opens new window)) - model: add model options (dcc874e (opens new window))
- schema: add
index
as a valid column attribute (8873e34 (opens new window)) - sql.js: add connection pool for managing sq.js backend (2df8381 (opens new window))
- types: add
'timestamp'
property type (6bd0710 (opens new window))
# BREAKING CHANGES
Major breakage inbound. See #14 (opens new window) for more info and useful migration tips.
# 0.10.0
(opens new window) (2016-12-17)
# BUG FIXES
- build: revert babel config to es2015 base (0e67048 (opens new window))
- tests: fix error in deletion tests (#4) (85160d8 (opens new window)), closes #4 (opens new window)
- tests: working directory discrepancy (3330d92 (opens new window))
# FEATURES
- addt'l createTable forms, coercion config, modularize, cjs export (d3bab02 (opens new window))
- change schemaBuilder & queryBuilder to getters (4c82d3c (opens new window))
# BREAKING CHANGES
- Any instances of retrieving knex's schema or query builder through trilogy must now use for example:
db.queryBuilder.[method]
instead ofdb.getQueryBuilder().[method]
. The same applies to schema builder. - Any commonjs users
require
ing trilogy no longer need.default
due to using commonjs export instead of Babel'sexport default
fill.