martabx

0.2.1 • Public • Published

MartabX

Knex Super Model

npm install martabx --save
Create Model
const MartabX = require('martabx')(knex)

const User = MartabX.model('User', {
  table: 'users',
  schema: {
    name: {
      type: 'string',
      required: true
    }
  }
})
SIMPLE CASE

Create

const user = await User.create({
  name: 'Sherina Munaf'
})

Get By Id

const user = await User.find(1)

or by another column

const user = await User.find({name: 'Gista Putri'})

or get motiple results

const user = await User.finds({published: 1})

Update

const user = await User.find(1)
user.name = 'Pramaisshela Arinda Daryono Putri'
user.update()

Get Count

const totalPublished = await User.count({published: 1})

Delete

const user = await User.find(1)
user.delete()
Extends Class
class UserChild extends User {
  async hardDelete () {
    const res = await context().query().where('id', this.id).delete()
    return res
  }
}

Using hannibal for schema

Readme

Keywords

none

Package Sidebar

Install

npm i martabx

Weekly Downloads

1

Version

0.2.1

License

cc by sa 4.0

Unpacked Size

29.6 kB

Total Files

19

Last publish

Collaborators

  • afief