Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/trailsjs/trailpack-knex
:package: Knex.js Trailpack
https://github.com/trailsjs/trailpack-knex
knex knexjs orm trailpack trails
Last synced: 7 days ago
JSON representation
:package: Knex.js Trailpack
- Host: GitHub
- URL: https://github.com/trailsjs/trailpack-knex
- Owner: trailsjs
- License: mit
- Created: 2016-01-22T09:02:25.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-11-20T21:50:26.000Z (almost 7 years ago)
- Last Synced: 2024-04-24T21:20:47.761Z (7 months ago)
- Topics: knex, knexjs, orm, trailpack, trails
- Language: JavaScript
- Homepage:
- Size: 57.6 KB
- Stars: 4
- Watchers: 6
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# trailpack-knex
[![NPM version][npm-image]][npm-url]
[![Build status][ci-image]][ci-url]
[![Dependency Status][daviddm-image]][daviddm-url]
[![Code Climate][codeclimate-image]][codeclimate-url]Provides support for database queries and schema migrations via [knex.js](http://knexjs.org/).
## Install
```sh
$ npm install --save trailpack-knex
```## Configure
#### `main.js`
```js
// config/main.js
module.exports = {
packs: [
// ... other trailpacks
require('trailpack-knex')
]
}
```#### `database.js`
```js
// config/database.js
module.exports = {
stores: {
knexPostgres: {
client: 'pg',/**
* knex connection object
* see: http://knexjs.org/#Installation-client
*/
connection: {
host: 'localhost',
user: 'admin',
password: '1234',
database: 'mydb'
}
}
},/**
* Supported Migrate Settings:
* - drop
* - create
*/
migrate: 'create',
defaultStore: 'knexPostgres'
}
```## Usage
### Models
```js
// api/models/User.js
class User extends Model {
static schema (table) {
table.increments('id').primary()
table.string('username')
table.string('firstName')
table.string('lastName')
}
}// api/models/Role.js
class Role extends Model {
static schema (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](https://github.com/trailsjs/trails/blob/master/.github/CONTRIBUTING.md) for more
information on how our projects are organized and how to get started.## License
[MIT](https://github.com/trailsjs/trails/blob/master/LICENSE)[npm-image]: https://img.shields.io/npm/v/trailpack-knex.svg?style=flat-square
[npm-url]: https://npmjs.org/package/trailpack-knex
[ci-image]: https://img.shields.io/travis/trailsjs/trailpack-knex/master.svg?style=flat-square
[ci-url]: https://travis-ci.org/trailsjs/trailpack-knex
[daviddm-image]: http://img.shields.io/david/trailsjs/trailpack-knex.svg?style=flat-square
[daviddm-url]: https://david-dm.org/trailsjs/trailpack-knex
[codeclimate-image]: https://img.shields.io/codeclimate/github/trailsjs/trailpack-knex.svg?style=flat-square
[codeclimate-url]: https://codeclimate.com/github/trailsjs/trailpack-knex