# Apatite
Object persistence framework for Node.js. ORM framework supports: MySQL, Oracle, Postgres, SQL Server, Sqlite.
Features
- Based on object oriented principles.
- Zero dependencies.
- Transaction based.
- Generate (or execute) SQL scripts to create tables/columns for models/attributes.
- Apart from standard mappings, supports inheritence mapping too.
- Optional objects session cache management.
Prerequisites
- Node version >=12.13.1.
- oracledb if you plan to use Oracle: $ npm install oracledb@4.1.0
- pg if you plan to use Postgres: $ npm install pg@6.1.5
- mysql if you plan to use Mysql: $ npm install mysql@2.17.1
- tedious if you plan to use Microsoft SQL Server: $ npm install tedious@2.0.0, optionally for connection pool: tedious-connection-pool : $ npm install tedious-connection-pool@1.0.5
- sqlite3 if you plan to use Sqlite: $ npm install sqlite3@3.1.8
Installation
C:\my-project> npm install apatite
Quick Start
-
Install the prerequisites.
-
Create your class and define a static method getModelDescriptor which takes apatite as an argument.
{ thisoid = 0; thisname = ''; } { console; } static { var table = apatite; var modelDescriptor = apatite; var column = table; column; modelDescriptor; column = table; modelDescriptor; return modelDescriptor; }
You could also create descriptor from a simple object:
static { var object = table: 'DEPT' model: this mappings: attr: 'oid' col: 'OID' pk: true type: 'serial' attr: 'name' col: 'NAME' type: 'varchar' length: 100 return apatite;}
- Register your models.
// Oraclevar connOptions = userName: 'apatite' password: 'apatite' connectionInfo: 'localhost/apatite' ;var apatite = ;
// Postgresvar connOptions = userName: 'apatite' password: 'apatite' connectionInfo: 'localhost/apatite' ;var apatite = ;
// Mysqlvar connOptions = userName: 'apatite' password: 'apatite' connectionInfo: 'localhost/apatite' ;var apatite = ;
// Mssqlvar connOptions = userName: 'apatite' password: 'apatite' connectionInfo: 'localhost/apatite' ;var apatite = ;
// Sqlitevar connOptions = connectionInfo: ':memory:' ;var apatite = ;
apatite;
- Create session and start querying your objects.
// Creates a new session and database connectionapatite; //closes the database connection { session}
// Using promise to execute queries// Creates a new session and database connectionapatite; //closes the database connection { session}
//query results from cursor streamapatite { session}
- Do changes to your objects and save.
... // Create new department var department = ; departmentname = 'Sales'; // Register it to session var { session; ; // must be called when you are done with all changes } session;...
... // Change an existing department var query = session; query; // Or you could create query from an array // const query = session.newQueryFromArray(Department, [['name', '=', 'Sales']]) query;...
... // Delete an existing department var { var query = session; query; // Or you could create query from an array // const query = session.newQueryFromArray(Department, [['name', '=', 'Pre-Sales']]) query; } session;...
Contributions
Welcome.
Links
Tests
Install all supported databases and then install dependencies:
C:\my-project> npm install
Run the tests:
C:\my-project> npm test