1.0.7 • Published 4 years ago

@kgrajan12/orm v1.0.7

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

gorm

This is a ORM and specially made for Mysql database.

Changes in this version

  • Migrate to Mysql2 from Mysql.
  • removed all callbacks make that all promise.

install CLI

install this orm cli first to initiate the setup

npm install -g @kgrajan12/orm

initiate Models

After installing the gorm globally then then you can run a single command to initiate all the models of the database in current folder

gorm

Note: Please confirm that you don't have any folder like /db

Folder structure

- /current_folder
|   - /db
    |   - /model
    |   |   - / <list of models>.js
    |   - /conn.json
    |   - /index.js

Now it is asking for database credentials. Ater giving the database credentials it generate model codes for you in /db/model

Example code

From the root folder of project

const { Village } = require('./db'); // Village is your table model

const village = new Village();

// select query
village.select({
    where: {
        region_id: 144,
        pin: 627111
    }
}).then((documents) => {
    <!--Do somthing with documents response-->
}).catch((error) => {
    console.log(error);
});

Probs

Select query props

propstypeusage
tablestringHere you can set different table name to Model mostly it is not used.
columnsarrayHere you can pass the list of columns to get that alone like select pin, region_id from village
whereobjectHere you can set the condition to select query.
likeobjectHere you can pass the pattern to select rows.
orderByarray of objectEx: [{ column: 'pin', asc: true }] you can pass like more objects to order column when select
joinobject of ModelHere you can pass other object of Model. So that you can join two tables.
onobjectThis is same like where prop but the only different is use of this prop. this is used to join tables with condition { "village.id": "people.village_id" } that means join when id of village equals village_id of people.
joinByarrayHere you can manage the operator between condition variables in on prop and it is iterativly used. ex: ['AND', 'OR'] first condition checked with AND, second condition is checked with OR and the next condition will use AND again
whereByarraysame like joinBy but the only different is used to manage where conditions
joinOperatorarraysame like joinBy itreation. but it is used to manage operators. ex: village.id=people.village_id you can pass here =, <>, <=, >=
whereOperatorarraysame like joinOperator, To manage where operators
joinTypestringyou can pass here the type of join INNER JOIN, OUTTER JOIN like that

Insert query props

propstypeusage
dataobjectex: {name: 'Teknik GG', village: 'Radhapuram'} to insert name and village feilds.
tablestringHere you can set different table name to Model mostly it is not used.

Update query props

propstypeusage
dataobjectex: {name: 'Teknik GG', village: 'Radhapuram'} to insert name and village feilds.
tablestringHere you can set different table name to Model mostly it is not used.
whereobjectHere you can set the condition to select query.
likeobjectHere you can pass the pattern to select rows.

Delete query props

propstypeusage
tablestringHere you can set different table name to Model mostly it is not used.
whereobjectHere you can set the condition to select query.
likeobjectHere you can pass the pattern to select rows.
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

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago