1.0.5 • Published 3 years ago

ormson v1.0.5

Weekly downloads
3
License
ISC
Repository
github
Last release
3 years ago

Ormson

Artisan ORM for JSON databases

Installation

  1. npm install ormson

Use

To use ORMSON you need to create the models you need within the path models/ and then require the index file that found in the models folder where you want to use it.

It is important to have installed the ormon client and have generated the necessary folder structure to be able to use Ormson.

More info: https://www.npmjs.com/package/ormson-cli

Template model

const Ormson = require('ormson');

class Product extends Ormson {
    constructor() {
        super();
        this.define({
            name: {
                type: String,
                required: true,
                validator: name => name.length > 10
            },
            price: {
                type: Number,
                required: true,
                validator: price => price > 0
            }
        }, {
            tablename: 'products',
            location: __filename
        });
    }
}

module.exports = Product;

Require example

 const { Product } = require('./database/models');

Methods

MethodDescriptionExample
findAll(option: callback)Search for multiple instances.Model.findAll();Model.findAll((row) => row.column == 'value');
findOne(callback)Find an instance by condition.Model.findOne((row) => row.column == 'value');
findByPk(id)Find an instance by id.Model.findByPk(12);
create(data: object)Create an instance.Model.create({ name: 'Car', year: 2020});
update(id, data: object)Update an instance by id.Model.create(12, { name: 'Truck', year: 2021});
destroy(id)Delete an instance by id.Model.destroy(12);
1.0.5

3 years ago

1.0.42

3 years ago

1.0.41

3 years ago

1.0.4

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago