1.1.5 • Published 5 months ago

@kamkam1_0/sql-orm v1.1.5

Weekly downloads
-
License
BSD 2
Repository
github
Last release
5 months ago

SQL-ORM

SQL-ORM is a module that allows you to interact very simply with your database

Installation

npm install @kamkam1_0/sql-orm

Functionalities

  • Create schemas
  • Make requests to your database easily

How to use

Required infos

const SQLORM = require("@kamkam1_0/sql-orm")
let ORM = new SQLORM({
    host: "127.0.0.1",
    user: "root",
    port: 3306,
    database: "NAME OF DATABASE"
})

Create a schema

Schemas allow you to create a pattern that you can create at any moment with a different name. It automatically create the missing columns, delete the ones not in your schema and update the others if needed.

ORM.createSchema({id: "ID", name: "NAME", autoCreate: false/true, columns: [{COLUMN_NAME: "VARCHAR(100)/INT/DATE"}, {COLUMN_TWO_NAME: "VARCHAR(100)/INT/DATE"}], autoInsert: [{COLUMN_NAME: "VALUE", COLUMN_TWO_NAME: "VALUE"}, {COLUMN_NAME: "VALUE", COLUMN_TWO_NAME: "VALUE"}]})

id

  • Mandatory
  • Type: String
  • With what you will be able to retrieve this schema to interact with it

name

  • Not mandatory
  • Type: String
  • Used to name the sql table if the module has to create it (if there is no name, the id will be used)

autoCreate

  • Not mandatory
  • Type: Boolean
  • Tells the module wether or not to create the table if it doesn't not exist.

columns

  • Mandatory
  • Array
  • Here, you specify each column of the table and its associated value

autoInsert

  • Not mandatory
  • Array
  • Here, you specify what the module should insert in the table if it doesn't contains it

Use the schema

The schema has the same functionnalities as the basic ORM. You just don't have to specify the table. (The table has to be created)

let test = 
ORM.createSchema({id: "ID", name: "NAME", autoCreate: false/true, columns: [{COLUMN_NAME: "VARCHAR(100)/INT/DATE"}, {COLUMN_TWO_NAME: "VARCHAR(100)/INT/DATE"}], autoInsert: [{COLUMN_NAME: "VALUE", COLUMN_TWO_NAME: "VALUE"}, {COLUMN_NAME: "VALUE", COLUMN_TWO_NAME: "VALUE"}]})
test.select({"COLUMN NAME": "VALUE"})
//Exemple: test.select({"ID": "54212154"})

Create the schema

Another way to create a schema without the autoCreate is the create method. If you gave an id/name and you want it to be the name of your table don't touch anything. You can also specify a new name to give to the table.

    test.create()
    //OR
    test.create("NEW_NAME")

Get/Delete Schema

    ORM.deleteSchema("ID")
    ORM.getSchema("ID")

General Use

All the SQL methods are available for use.

ORM.select("TABLE NAME", {"COLUMN NAME": "VALUE"})
//Exemple: ORM.select("login", {"ID": "54212154"})
1.1.5

5 months ago

1.1.1

6 months ago

1.1.0

6 months ago

1.1.4

6 months ago

1.1.3

6 months ago

1.1.2

6 months ago

1.0.29

11 months ago

1.0.28

12 months ago

1.0.27

1 year ago

1.0.30

11 months ago

1.0.26

1 year ago

1.0.25

1 year ago

1.0.24

1 year ago

1.0.23

1 year ago

1.0.22

1 year ago

1.0.21

1 year ago

1.0.20

1 year ago

1.0.19

1 year ago

1.0.18

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

1 year ago

1.0.13

1 year ago

1.0.12

1 year ago

1.0.11

1 year ago

1.0.10

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago