Socket
Socket
Sign inDemoInstall

ormie

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ormie

Dead-simple ORM for node using better-sqlite3


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Install size
6.72 kB
Created
Weekly downloads
 

Readme

Source

Ormie

A Dead-simple ORM for Node

What does this do?

Allows you to use an better-sqlite3 store for your node app with queries precomposed from your types.

How do I use this?

Create a type with name and schema, e.g.,

class Cat {
  // Without tableName, the table would be named 'Cat'
  static get tableName() {
    return 'cats';
  }
  // Describes the table; you can use standard SQLite types here, as well as `primary key`, `unique`, etc.
  static get schema() {
    return {
      name: 'text primary key',
      age: 'integer'
    }
  }
  constructor({ name, age }) {
    this.name = name;
    this.age = parseInt(age, 10);
  }
}

Create an ORMie table from the database and type:

const Ormie = require('ormie');

const cats = new Ormie(db, Cat);

If you need a couple different tables of cats, you can do that:

const otherCats = new Ormie(db, {
  name: 'otherCats',
  schema: Cat.schema
});

Once you have your table, you can start making queries:

// Your table will not exist until you do this.
cats.create();

// Add a cat
cats.insert({ name: 'Nutmeg', age: 4 });

// Find cats matching a description
cats.find({ name: 'Nutmeg' });

> [ Cat { name: 'Nutmeg', age: 4 } ]

// Find just one cat
cats.first({ name: 'Nutmeg' });

> Cat { name: 'Nutmeg', age: 4 }

// Get the age of a named cat

cats.first({ name: 'Nutmeg', _cols: 'age' })

> 4

// Update any cat named 'Nutmeg' with an age of `5`

cats.update({ age: 5 }, { name: 'Nutmeg' });

// Remove some cats

cats.remove({ age: 5 });

// Drop the cats table

cats.drop();

There are some special search parameters:

_cols: An array or string. If present, your object will not be instantiated; you'll just get data back. If it's a string, your results will be stripped down to the raw type in the database for that one column.

_sort: Order your results by a name or array of names, optionally with a direction (e.g., name:desc)

_limit: Limit your results to some number.

_offset: Only valid if _limit is present; will shift your results by the number specified.

Keywords

FAQs

Last updated on 13 Feb 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc