Skip to content

Releases: haltcase/trilogy

v2.0.5

08 Aug 04:01
Compare
Choose a tag to compare
BUG FIXES
  • ensure timestamps/schema options are handled properly (#112) (a30b29c)

v2.0.4

08 Aug 02:29
Compare
Choose a tag to compare
BUG FIXES

v2.0.3

20 Jun 14:47
Compare
Choose a tag to compare
BUG FIXES
  • types: allow providing value type to getRaw (a41da36)

v2.0.2

30 Jun 06:21
Compare
Choose a tag to compare
BUG FIXES
  • escape input values in raw queries (43d0558)
  • pass descriptor properties to knex properly (63c9569)

v2.0.1

24 Jun 04:42
Compare
Choose a tag to compare
BUG FIXES
  • timestamps: only create timestamp triggers when necessary (35dbab6)

v2.0.0

17 Jun 14:34
Compare
Choose a tag to compare

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:

trilogy-og

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 of onQuery hook (cf7d085)
  • invariant: throw standard Error instead of custom type (5a4bf70)
  • schema: make nullable actually work inversely to notNullable (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 to countIn (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 & notNullable properties will cause an Error to 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 are Errors instead.
  • flow: flow definitions have been removed.
  • find*: 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.
  • count: model.count no longer has a signature allowing a column as the first parameter. This is now a separate method called countIn.
  • 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 to increment & 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 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:')

v2.0.0-rc.5

13 Jun 02:49
Compare
Choose a tag to compare
v2.0.0-rc.5 Pre-release
Pre-release
yarn add trilogy@2.0.0-rc.5

v2.0.0-rc.4

12 Jun 14:49
Compare
Choose a tag to compare
v2.0.0-rc.4 Pre-release
Pre-release
yarn add trilogy@2.0.0-rc.4

v2.0.0-rc.3

29 Jan 21:24
Compare
Choose a tag to compare
v2.0.0-rc.3 Pre-release
Pre-release
yarn add trilogy@2.0.0-rc3

v2.0.0-rc.2

19 Aug 17:46
Compare
Choose a tag to compare
v2.0.0-rc.2 Pre-release
Pre-release
yarn add trilogy@2.0.0-rc.2