5.0.14 • Published 1 year ago

bh-modelbase v5.0.14

Weekly downloads
3
License
MIT
Repository
github
Last release
1 year ago

modelbase

Typed base model for use with the incredible knex query builder: https://knexjs.org/

  • transform object keys to snake case for storage, and camelcase on the way out
  • typed queries and operations if you're into that

usage

// store_model.ts
import BaseModel from 'bh-modelbase';
import initDB from '../../lib/db';

type Store = {
  id: string,
  userId: string,
  name: string,
};

export default class StoreModel extends BaseModel<Store> {
  constructor(db) {
    const table = 'store';
    super(db, table);
  }
}

async function run() {
  const db = await initDB();
  const storeModel = new StoreModel(db);
  
  let stores = await storeModel.fetchAll();
  // []
  
  const store = await storeModel.create({
    id: '123',
    userId: '234',
    name: 'this is a store',
  });
  // { id: '123', userId: '234', name: 'this is a store' }
  
  const newStores = await storeModel.fetchAll();
  // [ { id: '123', userId: '234', name: 'this is a store' } ]
  await db.destroy();
}

run().catch(err => console.log(err));
5.0.6

1 year ago

5.0.5

1 year ago

5.0.10

1 year ago

5.0.11

1 year ago

5.0.12

1 year ago

5.0.13

1 year ago

5.0.14

1 year ago

5.0.9

1 year ago

5.0.8

1 year ago

5.0.7

1 year ago

4.0.5

2 years ago

4.0.4

2 years ago

4.0.3

2 years ago

4.0.2

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

2.2.0

2 years ago

2.0.11

3 years ago

2.1.0

3 years ago

2.0.9

3 years ago

2.0.7

3 years ago

2.0.8

3 years ago

2.0.6

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

1.0.1

3 years ago

2.0.0

3 years ago

1.0.0

4 years ago