easyormdeprecated

Easyorm is a promise-based Node.js ORM for Postgres, MySQL, SQLite and Microsoft SQL Server.

Usage no npm install needed!

<script type="module">
  import easyorm from 'https://cdn.skypack.dev/easyorm';
</script>

README

Easyorm

Easyorm is a promise-based Node.js ORM for Postgres, MySQL, SQLite and Microsoft SQL Server.

npm install easyorm

The following types of data can be defined in easyorm: STRING, INT, UINT, SHORT, USHORT, LONG, ULONG, ARRAY, OBJECT, LIST, MAP.

Among them, STRING, INT, UINT, SHORT, USHORT, LONG, ULONG, ARRAY are simple types, divided in the main table.

OBJECT is defined as the package type, itself does not participate in the division, but OBJECT elements involved.

The LIST, MAP is treated as a complex type, divided in the sub-table.

It should be noted that the ARRAY, LIST difference, ARRAY elements must be simple type, LIST elements apply to all types.

In addition, "_key" for LIST and MAP must be simple type.

Using the above data types, you can easily define the data structure, like this:

{
    "_type": "OBJECT",
    "_value": {
        "name": {
            "_type": "STRING"
        },
        "age": {
            "_type": "USHORT"
        },
        "school": {
            "_type": "OBJECT",
            "_value": {
                "name": {
                   "_type": "STRING"
                },
                "address": {
                   "_type": "STRING"
                }
            }
        },
        "courses": {
            "_type": "LIST",
            "_value": {
                "_type": "OBJECT",
                "_value": {
                   "name": {
                       "_type": "STRING"
                   },
                   "book": {
                       "_type": "STRING"
                   },
                   "time": {
                       "_type": "ARRAY",
                       "_value": {
                           "_type": "UINT"
                       }
                   },
                   "teacher": {
                       "_type": "MAP",
                       "_key": {
                           "_type": "UINT"
                       },
                       "_value": {
                           "_type": "OBJECT",
                           "_value": {
                               "name": {
                                  "_type": "STRING"
                               },
                               "age": {
                                  "_type": "UINT"
                               }
                           }
                       }
                   }
                }
            }
        }
    }
}

Easyorm's API is also very simple, you can create table like this:

let Model = require('easyorm').Model;
let student = new Model('student', schema, config);
student.createTable(function (err) {

});

insert data like this:

student.insert(id, dataObj, function (err) {

});

query data like this:

student.query(id, function (err) {

});

delete data like this:

student.del(id, function (err) {

});

update data like this:

student.update(id, data, function (err) {

});

config database connector like this:

{
    "client": "mysql",
    "connection": {
        "host"     : "192.168.68.128",
        "user"     : "root",
        "password" : "123456",
        "database" : "test"
    },
    "pool": {
        "min": 0,
        "max": 7
    }
}

Have fun !