1.2.0 • Published 2 years ago

db-datalayer-js v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Maintainer Source Code Latest Version Software License

Datalayer-JS

The datalayer-js is a persistent abstraction component of your database that serverless-mysql has prepared instructions for performing common routines such as registering, reading, editing, and removing data.

Highlights

  • Easy to set up (Fácil de configurar)
  • Total CRUD abstraction (Abstração total do CRUD)
  • Create safe models (Crie de modelos seguros)

INSTALLATION AND USAGE

DataLayer-js is available via NPM:

  npm i db-datalayer-js

on the root of the project create a .env file with the following contents.

  DRIVER = mysql
  HOST = <YOUR HOST>
  PORT = 3306
  USER = <YOUR USER>
  PASSWORD = <YOUR PASS>
  DATABASE = <YOUR DATABASE>

then you create a folder named models, create a model like this:

  import DataLayer from "db-datalayer-js";

  class User extends DataLayer {
    constructor() {
        // entity, required, primary and timestamps
        super("users", [], "id", true)
    }
  }

Now you are ready to use the datalayer function :D

DOCS

  • find

    This is a select from your database

    await user.find().fetch() // same: SELECT * FROM users

    example with all params

    await user.find({ 
      entity_nickname: "user",
      columns: ["user.username", "users_roles.name as role"],
      joins: [{
        type: "left",
        table: "users_roles",
        conditions: ["user.role_id = users_roles.id"]
      }],
      where: [
        "user.username = 'teste'"
      ],
      limit: 1,
      group_by: "user.id",
      order_by: "user.id"
    }).fetch(true)
  • findById

    	```javascript
    	await user.findById(7).
    	```
  • create

    	```javascript

    await user.create({ name: "value", }).save()

    // Multiple lines insert

    await produtos.create( {code:"000", name:"teste 1",value: 1.5}, {code:"001", name:"teste 1", value: null}, ).save();

    	```
  • update

    	```javascript

    await user.update({ name: "value", })

    	```
  • delete
    	```javascript
    let current_user = user.findById(4); // param is bool, default value is false and it will update your deleted_at column in your database. // when is true the method will delete the current_user current_user.destroy()
    	```

HELP ME, CONTRIBUTE

you can do it just make a pull request, I'll be happy XD

1.2.0

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago