https://github.com/matter-in-motion/mm-db-schema
Database schema defenition extension
https://github.com/matter-in-motion/mm-db-schema
database extension matter-in-motion schema
Last synced: 2 months ago
JSON representation
Database schema defenition extension
- Host: GitHub
- URL: https://github.com/matter-in-motion/mm-db-schema
- Owner: matter-in-motion
- Created: 2017-08-29T14:58:05.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-05-16T03:06:29.000Z (about 8 years ago)
- Last Synced: 2025-01-30T03:33:32.868Z (over 1 year ago)
- Topics: database, extension, matter-in-motion, schema
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Matter In Motion. Database schema extension
[](https://www.npmjs.com/package/mm-db-schema)
[](https://www.npmjs.com/package/mm-db-schema)
Database schema defenition extension for [matter in motion](https://github.com/matter-in-motion/mm) framework
## Usage
[Extensions installation instructions](https://github.com/matter-in-motion/mm/blob/master/docs/extensions.md)
1. Add this extension
2. Add schema extension for your database
Define a schema in your resource controller with options:
* __db__ — database name. If you use [mm-db](https://github.com/matter-in-motion/mm-db) extension you can omit this. Default database will be used.
* __table__ — table name or an object with table name and table creation options.
* __indexes__ — array of index names or an object with index names and index creation options.
* __apply__ — function. If you define `apply` function it will be called. `table` and `indexes` options will be ignored. However, you still should still define them to use in your code.
You can define as many tables as you want.
### Simple example
```js
Controller.prototype.schema = {
name: {
table: 'table_name',
indexes: ['index_name1', 'index_name2']
}
}
```
### Full example
```js
Controller.prototype.schema = {
name: {
db: 'database driver name',
table: {
'table_name': tableOptions
},
indexes: {
'index_name1': indexOptions1,
'index_name2': indexOptions2,
}
}
}
```
### Complicated scenarios
```js
Controller.prototype.schema = {
name: {
db: 'database driver name',
//this will be used as description only
table: 'table_name',
indexes: ['index_name1', 'index_name2'],
//here is actual schema
apply: function(dbDriver, schema) {
//do any stuff nessesary and return a promise
}
}
}
```
License: MIT.