-
Notifications
You must be signed in to change notification settings - Fork 1
node
waterfoul edited this page Aug 11, 2016
·
15 revisions
- Install extra dependancies for node support
npm install sequlize typings install --save sequelize typings install --save --global env~node
- Install a database driver supported by sequelize.
As of writing this you need one of the following
npm install --save pg pg-hstore npm install --save mysql npm install --save sqlite3 npm install --save tedious // MSSQL
- In your index file add the following
Note: You can also add a fourth paramter of type sequelize.Options
import {connect} from 'tanjentjs-ts-orm/node'; connect('databaseName', 'username', 'password')
- Create a base contract which contains a module name, this will get used to uniquely identify tables comming from your module
import {DataContract} from 'tanjentjs-ts-orm/node'; class BaseContract { public static moduleName = 'test'; }
- Create your object file
Note: The constructor line and injector import are only necessary if you want to use the angular2 connector.
import {BaseContract} from 'location/of/baseContract/file'; import {DataConnection, register, field} from 'tanjentjs-ts-orm/node'; import {Injector} from '@angular/core'; export class UserContract extends BaseContract { @field() public username: string; } @register('core') export class User extends DataConnection<UserContract> { constructor(private injector?: Injector) { super(injector); } protected getContract() { return UserContract; } }
- Use the DataConnection object, it should have methods which return promises to your DataContract object
- If you want to use foreign key relationships see relationships
If you need extra logging you can get it one of two ways.
- Set DEBUG=ts-orm:* as an environment variable
- Use DEBUG=ts-orm:*,ts-orm-info:* for more verbose logging
- Supply a fifth parameter to connect which conforms to the node.ILogger interface