Neologistic Paraphasic Mumbling

    @fabrix/spool-knex
    TypeScript icon, indicating that this package has built-in type declarations

    1.6.1 • Public • Published

    spool-knex

    Gitter NPM version Build Status Test Coverage Dependency Status Follow @FabrixApp on Twitter

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

    Install

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

    Configure

    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'
    }

    Usage

    Models

    // 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')
      }
    }

    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

    Install

    npm i @fabrix/spool-knex

    DownloadsWeekly Downloads

    0

    Version

    1.6.1

    License

    MIT

    Unpacked Size

    22.2 kB

    Total Files

    42

    Last publish

    Collaborators

    • scottbwyatt