Home

Awesome

<p align="center"> <img src="https://raw.githubusercontent.com/citycide/trilogy/master/media/logo.svg?sanitize=true" width="420" alt="trilogy"> <br> <a href="https://www.npmjs.com/package/trilogy"><img src="https://flat.badgen.net/npm/v/trilogy" alt="Version"></a> <a href="https://www.npmjs.com/package/trilogy"><img src="https://flat.badgen.net/npm/license/trilogy" alt="License"></a> <a href="https://travis-ci.org/citycide/trilogy"><img src="https://flat.badgen.net/travis/citycide/trilogy" alt="Travis CI"></a> <a href="http://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html"><img src ="https://flat.badgen.net/badge/written%20in/TypeScript/294E80" alt="Written in TypeScript"></a> <a href="https://standardjs.com"><img src="https://flat.badgen.net/badge/code%20style/standard/green" alt="JavaScript Standard Style"></a> <a href="https://gitter.im/citycide/trilogy"><img src="https://flat.badgen.net/badge/chat/on%20gitter/green" alt="Gitter"></a> </p>

trilogy is a simple Promise-based wrapper for SQLite databases. It supports both the native C++ sqlite3 driver and the pure JavaScript sql.js backend — compile natively for speed when you need it, or use sql.js headache-free in cross-platform environments and Electron apps.

It's not an ORM and isn't intended to be one — it doesn't have any relationship features. Instead it focuses on providing a simple, clear API that's influenced more by Mongoose than by SQL.


features · installation · usage · contributing · license


features

installation

  1. Install trilogy

    # using yarn
    yarn add trilogy
    
    # using npm
    npm i trilogy
    
  2. Install a backend

    # using yarn
    yarn add sqlite3
    
    # using npm
    npm i sqlite3
    

    or

    # using yarn
    yarn add sql.js
    
    # using npm
    npm i sql.js
    

usage

Full documentation is available here and includes guides, an API reference, and more.

Here's a quick overview. It uses async & await but is easily usable with vanilla Promises.

import { connect } from 'trilogy'

// defaults to using the `sqlite3` backend
const db = connect('./file.db')

// choose `sql.js` to avoid native compilation :)
const db = connect('./file.db', {
  client: 'sql.js'
})

// set the filename to ':memory:' for fast, in-memory storage
const db = connect(':memory:', {
  // it works for both clients above!
  client: 'sql.js'
})

;(async function () {
  const games = await db.model('games', {
    name: { type: String },
    genre: String,            // type shorthand
    released: Date,
    awards: Array,
    id: 'increments'          // special type, primary key
  })

  await games.create({
    name: 'Overwatch',
    genre: 'FPS',
    released: new Date('May 23, 2016'),
    awards: [
      'Game of the Year',
      'Best Multiplayer Game',
      'Best ESports Game'
    ]
  })

  const overwatch = await games.findOne({ name: 'Overwatch' })

  console.log(overwatch.awards[1])
  // -> 'Best Multiplayer Game'
})()

contributing

This project is open to contributions of all kinds! Don't worry if you're not 100% up to speed on the process — there's a short outline in the Contributor Guide.

You'll also find a reference for the set of labels used to categorize issues, with descriptions of each. (Contributor Guide - issue labels)

Also, please read and follow the project's Code of Conduct.

license

MIT © Bo Lingen / citycide

See license