Spool: Knex Datastore
@fabrix/spool-knex"">
Provides support for database queries and schema migrations via knex.js.
$ npm install --save @fabrix/spool-knex
main.ts
// config/main.ts
export const main = {
spools: [
// ... other spools
require('@fabrix/spool-knex').KnexSpool
]
}
database.ts
// config/stores.ts
export const stores = {
knexPostgres: {
orm: 'knex',
client: 'pg',
/**
* knex connection object
* see: http://knexjs.org/#Installation-client
*/
connection: {
host: 'localhost',
user: 'admin',
password: '1234',
database: 'mydb'
}
}
}
// config/models.ts
export const models = {
/**
* Supported Migrate Settings:
* - drop
* - create
*/
migrate: 'create',
defaultStore: 'knexPostgres'
}
// api/models/User.ts
class User extends Model {
static schema (app, table) {
table.increments('id').primary()
table.string('username')
table.string('firstName')
table.string('lastName')
}
}
// api/models/Role.ts
class Role extends Model {
static schema (app, table) {
table.increments('id').primary()
table.string('name')
table.integer('user_id').references('user.id')
}
}
SchemaMigrationService
create
Create the schema using knex
drop
Drop the schema using knex
alter
Not currently supported.
We love contributions! Please check out our Contributor’s Guide for more
information on how our projects are organized and how to get started.