npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

masterquest-sqlite3

v1.3.1

Published

A NoSQL / SQLite3 Hybrid. All your indices are belong to us. Master Quest.

Downloads

36

Readme

Master Quest SQLite3

Master Quest is a brave new attempt at Data Mapping.

It kinda looks like an ORM, but it isn't. It's not SQL, it's NoSQL with benefits.

You get to choose which contraints to keep and which to forget.

Guiding Principles

  • NoSQL (well, as far as you care)
  • Migrations don't suck
  • Harness the awesomeness of indexes
  • deletedAt to delete a record
  • null to delete a field
  • unindexed fields stored as json
  • ids should be one either
    • deterministic (duplicate records not okay, last updatedAt wins)
    • cryptographically random (duplicate records consolidated in application)
  • avoid mutating data (CRDT-ish style)
  • if it won't scale, don't fret it (no foreign key contraints)
  • id is simply named id
  • multi-key ids should be sha256sum(key1 + key2 + key3)
  • JavaScript is camelCasey, databases are snake_casey. We can handle that.
  • join tables are in alphabet order i.e. foo, bar, bar_foo

TODO / In Progress

  • Multi-Master Replication
  • Relationships
    • currently detaches before saving (most important)
  • MongoDB / RethinkDB -ish queries
  • RealTime

USAGE

npm install --save 'https://github.com/coolaj86/node-masterquest-sqlite3.git'
'use strict';

// works with sqlite3, sqlcipher, and sqlite3-cluster
var db = new (require('sqlite3').Database)('/tmp/data.sqlite3');

require('masterquest-sqlite3').wrap(db, {
  modelname: 'Persons'
, indices: [ 'firstName', 'lastName' ]
, hasMany: [ 'children' ]
}).then(function (mq) {

  // update (or create) deterministic record
  var john = {
    id: '[email protected]'
  , firstName: 'john'
  , lastName: 'doe'
  , dog: { name: 'ralph', color: 'gold' }
  , children: [ '[email protected]' ]
  };

  mq.Persons.upsert(john.id, john).then(function () {
    // note: if `dog` existed, it will be overwritten, not merged
    // note: `children` will be removed before save

    mq.Persons.get('[email protected]').then(function (data) {
      // dog will be rehydrated from json
      // children will not be fetched and attached
      console.log(data);
    });

  });

});

API

It's kinda CRUDdy... but don't let that scare you.

  • upsert(id, data[, oldId]) - creates or updates based on existence in DB (use this)
    • modifies createdAt and or updatedAt
  • create(id, obj) - same as above, but fails if the object exists
  • save(data[, oldId]) - (just don't use this, please) creates or updates based on presence of ID
  • destroy(id) - mark a record as deletedAt from DB
  • get(id) - grab one by id
  • find(attrs, opts) - grab many by indexable attributes
    • attrs
      • explicit null will find all (and requires that limit be set)
      • { foo: 2, bar: 6 } will find records where foo is 2 and bar is 6
    • opts
      • orderBy
      • orderByDesc
      • limit

Schema

Anything that isn't in the schema

  • indices specifies an array of strings
    • [ 'firstName', 'lastName' ]
  • relationships are option and current only exclude during save
    • hasMany, belongsTo, hasOne, belongsToMany, hasAndBelongsToMany
  • createdAt, updatedAt, deletedAt timestamps are always added
    • turn off with timestamps: false
  • id is always id
    • change with idname: 'myId'

Migrations

You can only add indexes. You cannot rename or remove them.

To add an index, simply change the schema.

{ modelname: 'persons'
, indices: [ 'firstName', 'lastName' ]
, hasMany: [ 'children' ]
}

LICENSE

Dual-licensed MIT and Apache-2.0

See LICENSE