0.2.1 • Published 6 years ago

martabx v0.2.1

Weekly downloads
56
License
cc by sa 4.0
Repository
-
Last release
6 years ago

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

0.2.1

6 years ago

0.2.0

6 years ago

0.1.2

6 years ago

0.1.1

7 years ago

0.1.0

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago