Git Product home page Git Product logo

trilogy's Introduction

trilogy
Version License Travis CI JavaScript Standard Style

trilogy is a Promise-based layer over SQLite, featuring type-casting schema models and allowing both native & pure JavaScript backends ( and in-memory databases ).


features

  • Model your tables with native JavaScript

    Set up database tables with types like String, Date, and 'increments' - and trilogy will handle all the type-casting involved so that you always receive what you expect to receive.

  • Uses knex to build queries

    trilogy uses knex internally to build its queries - but it's also exposed so you can use it to build your own ultra-complex queries. No need to mess with ridiculous multi-line strings.

  • Swappable SQLite backends ( plus in-memory storage )

    trilogy supports both the native sqlite3 module as well as sql.js - meaning you can easily embed a SQLite database without a compilation step like gyp, which can get a little tricky when dealing with multiple platforms or architectures.

    You can even swap the backend after you've started, with no changes to the rest of your code! ๐ŸŽ‰

  • trilogy โค๏ธ Electron & NW.js

    If you've run into issues using sqlite3 in Electron or NW.js, like many have before you, you can easily use trilogy with the sql.js backend, which doesn't need to be compiled at all! Plus, you still get all the greatness of a simple API and all the raw power of knex's query building - wrapped in a neat little package. ๐ŸŽ

installation

  1. Install Trilogy

    npm i trilogy
  2. Install a backend

    npm i sqlite3

    or

    npm i sql.js

usage

See the documentation here for the full API - including usage syntax and examples.

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

import Trilogy from 'trilogy'

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

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

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

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

  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

Contributions are welcome! Feel free to open an issue or submit a pull request. For large changes, please open an issue to discuss the revisions first.

license

MIT ยฉ Bo Lingen / citycide

See LICENSE

trilogy's People

Contributors

greenkeeper[bot] avatar haltcase avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.