TypeScript, to a database schema, using decorators. Support for SQLite is
available through the separate module
orm-js-sqlite, support for other
databases is planned.
async/await in TypeScript.
Take a look at the following code snippet:
;// mark the following class as an entity
The entity name (
User) as well as the property names and types are
automatically determined by orm-js, you don't need to take care of the naming
(unless you have two entities with the same name).
Properties missing the
@orm.field() decorator will not be saved to the
database, the field won't be created in the schema. You can optionally use
@orm.id() for a single field to mark it as the primary key, which is used to
uniquely identify a single data record.
several of them in a single file. It's your responsibility to load all these
files in order to use the orm-js system. For example, you can put all your
entity files in a single directory, which you can scan for files to
In this example, a simple
require('./user') is enough to tell
this entity (because of the
After you've loaded all your entities, you can connect to your database and use
orm-js itself does not provide connection to a database. Currently there's
orm-js-sqlite available. Before you can use orm-js (you may load your
entities before, however), you have to bind a database connection:
The database schema (the tables, fields, relations etc.) is managed by
you usually can't use any existing schema. After you've loaded your entities and
connected to your database, you use
build() to create a new database schema:
In order to get or save entity objects, you can use the
orm-js/orm. For each entity, you have to instanciate a new
Repository with the entity class passed as its parameter. The following
example creates a new user and retrieves it back from the database:
$ npm install orm-js
You'll need to install a database connector for orm-js, in order to connect to
an actual database. Currently there's only
$ npm install orm-js-sqlite
When using TypeScript, make sure to enable both
emitDecoratorMetadata in your tsconfig.json:
orm-js is licensed under the MIT License.