1.0.21 • Published 4 years ago

com.siteblade.database.orm v1.0.21

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

com.siteblade.database.orm

Database ORM featuring:

  • Typed Entity properties
  • Support for (flags) enum classes via com.siteblade.util

Getting started

This is what an entity looks like:

src/entities/User.js

Connecting to database:

Migrations and seeds

This package contains a CLI which supports entity migrations and seeds. For one application to work, it must apply the corresponding migrations.

To install the CLI, run:

$ npm install -g com.siteblade.database.orm

To use the CLI, you'll need a configuration file. For this you can run dborm init on your project.

The following command will create a migration based on one Entity class.

$ dborm g migration -c MyEntity

The copy option (-c) may be repeated. Note that every specified copy is equivalent to table creation and not table alteration. Table alteration must be currently manually scripted into a migration using the MigrationContext.

TIP A migration can be renamed in the format 0.someLabel.js where 0 is the migration number.

The following commands will apply specific migrations:

$ dborm migrate 0
$ dborm migrate:latest
$ dborm migrate:rollback

API

A corresponding JSDoc tool is on work yet.

Adding, finding and paginating

import { OrderBy, ItemsPerPage, Comparison } from 'com.siteblade.databaseorm';

// all descending entities
await MyEntity.all( OrderBy('updatedAt', 'desc') );

// ascending entities with (x, y)
await MyEntity.find( { x, y, }, OrderBy('updatedAt', 'asc') );

// first page
let p = await MyEntity.page( 0, ItemsPerPage(10) );
console.log( p.total, p.pageNumber, p.results );
console.log( p.toJSON() );

// paginating with constraints
await MyEntity.page( 0, { x, y } );

// delete where...
await MyEntity.deleteWhere( { x, y } );

// adding Entity data
await MyEntity.add( { x, y } );

// Comparison constraints
await MyEntity.find( { x: Comparison('>', 10) } );

Miscellanous

await entity.delete();

// average
await MyEntity.average( 'x' );

// average with constraints
await MyEntity.average( 'x', { x, y } );
1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago