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.,
// Without tableName, the table would be named 'Cat' static { return 'cats'; } // Describes the table; you can use standard SQLite types here, as well as `primary key`, `unique`, etc. static { return name: 'text primary key' age: 'integer' } { thisname = name; thisage = ; }
Create an ORMie table from the database and type:
const Ormie = ; const cats = db Cat;
If you need a couple different tables of cats, you can do that:
const otherCats = db name: 'otherCats' schema: Catschema;
Once you have your table, you can start making queries:
// Your table will not exist until you do this.cats; // Add a catcats; // Find cats matching a descriptioncats; > Cat name: 'Nutmeg' age: 4 // Find just one catcats; > Cat name: 'Nutmeg' age: 4 // Get the age of a named cat cats > 4 // Update any cat named 'Nutmeg' with an age of `5` cats; // Remove some cats cats; // Drop the cats table cats;
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.