项目作者: fabrix-app

项目描述 :
Spool: Knex Datastore
高级语言: TypeScript
项目地址: git://github.com/fabrix-app/spool-knex.git
创建时间: 2018-07-09T18:20:36Z
项目社区:https://github.com/fabrix-app/spool-knex

开源协议:Other

下载


spool-knex

Gitter
@fabrix/spool-knex"">NPM version
Build Status
Test Coverage
Dependency Status
Follow @FabrixApp on Twitter

Provides support for database queries and schema migrations via knex.js.

Install

  1. $ npm install --save @fabrix/spool-knex

Configure

main.ts

  1. // config/main.ts
  2. export const main = {
  3. spools: [
  4. // ... other spools
  5. require('@fabrix/spool-knex').KnexSpool
  6. ]
  7. }

database.ts

  1. // config/stores.ts
  2. export const stores = {
  3. knexPostgres: {
  4. orm: 'knex',
  5. client: 'pg',
  6. /**
  7. * knex connection object
  8. * see: http://knexjs.org/#Installation-client
  9. */
  10. connection: {
  11. host: 'localhost',
  12. user: 'admin',
  13. password: '1234',
  14. database: 'mydb'
  15. }
  16. }
  17. }
  18. // config/models.ts
  19. export const models = {
  20. /**
  21. * Supported Migrate Settings:
  22. * - drop
  23. * - create
  24. */
  25. migrate: 'create',
  26. defaultStore: 'knexPostgres'
  27. }

Usage

Models

  1. // api/models/User.ts
  2. class User extends Model {
  3. static schema (app, table) {
  4. table.increments('id').primary()
  5. table.string('username')
  6. table.string('firstName')
  7. table.string('lastName')
  8. }
  9. }
  10. // api/models/Role.ts
  11. class Role extends Model {
  12. static schema (app, table) {
  13. table.increments('id').primary()
  14. table.string('name')
  15. table.integer('user_id').references('user.id')
  16. }
  17. }

Services

SchemaMigrationService

create

Create the schema using knex

drop

Drop the schema using knex

alter

Not currently supported.

Contributing

We love contributions! Please check out our Contributor’s Guide for more
information on how our projects are organized and how to get started.

License

MIT