• Stars
    star
    261
  • Rank 156,630 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

TypeScript SQLite layer with support for both native C++ & pure JavaScript drivers.

trilogy
Version License Travis CI Written in TypeScript JavaScript Standard Style Gitter

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

  • ๐Ÿ”— automatically casts data between JavaScript & SQLite types

    Define schemas with types like String, Date, or 'increments' โ€” trilogy will handle all the type-casting involved to map accurately between JavaScript and the underlying SQLite database.

  • ๐Ÿ”‹ powered by the knex query builder

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

  • ๐Ÿ”ฉ supports multiple swappable backends ( plus in-memory storage )

    Both the native sqlite3 module and sql.js (pure JavaScript!) are supported. There is also memory-only storage for fast, unpersisted data handling, which is great for tests and performance critical situations.

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

  • ๐Ÿ‘ฎ written in TypeScript

    trilogy is written in and provides a first-class experience for TypeScript.

  • ๐Ÿ”Œ lifecycle hooks

    Any number of hooks (aka subscribers or listeners) can be attached at several points in the lifecycle โ€” for example onQuery, beforeCreate, afterUpdate. These are useful for debugging and extensibility.

  • ๐Ÿ’ž perfect for Electron & NW.js

    Compiling the sqlite3 module for all the platforms you target with Electron or NW.js can be difficult. That's why trilogy also supports the sql.js backend, which doesn't need to be compiled at all!

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

More Repositories

1

param.macro

Partial application syntax and lambda parameters for JavaScript, inspired by Scala's `_` & Kotlin's `it`
JavaScript
186
star
2

cascade

Method, accessor, and assignment cascades for Nim, inspired by Smalltalk & Dart.
Nim
96
star
3

tablemark

Generate markdown tables from JSON data.
TypeScript
77
star
4

glob

Pure Nim library for matching file paths against Unix style glob patterns.
Nim
62
star
5

babel-plugin-partial-application

[DEPRECATED] Please use https://github.com/citycide/param.macro
JavaScript
58
star
6

fugitive

Simple command line tool to make git more intuitive, along with useful GitHub addons.
Nim
32
star
7

tablemark-cli

Generate markdown tables from JSON data at the command line.
TypeScript
15
star
8

namesake-cli

Find available & relevant npm package names from the command line.
JavaScript
6
star
9

babel-preset-modern-async

[DEPRECATED] Cutting edge Babel preset using 'fast-async' instead of generators for async/await. Also configurable with Electron & Bluebird.
JavaScript
3
star
10

namesake

Find available & relevant npm package names for your project.
JavaScript
3
star
11

strat

Functional-ish JavaScript string formatting, with inspirations from Python. TypeScript friendly.
JavaScript
2
star
12

singularity

JavaScript
1
star
13

changelog

Customized and updated fork of `standard-changelog`
JavaScript
1
star
14

pkg.macro

Fetch properties of your project's `package.json` at compile time.
TypeScript
1
star
15

arify

[DEPRECATED] JavaScript function overloading. Let your function focus on its function.
JavaScript
1
star
16

vscode-cosmos

Through the cosmos, darkly: a set of dark, flat, material-esque themes for Visual Studio Code.
1
star
17

tryad

Monadic mashup of Maybe & Either that represents a value, nothing, or an error. Promise friendly.
JavaScript
1
star
18

babel-standalone

A smaller customized version of @babel/standalone.
JavaScript
1
star
19

if-ci

Easily run npm scripts only when in a CI environment.
JavaScript
1
star
20

converge

Extensible command-line Twitch bot.
JavaScript
1
star
21

stunsail

Super opinionated collection of utility functions.
JavaScript
1
star