Skip to content
waterfoul edited this page Aug 11, 2016 · 15 revisions
  1. Install extra dependancies for node support
    npm install sequlize
    typings install --save sequelize
    typings install --save --global env~node
  2. 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
  3. In your index file add the following
    import {connect} from 'tanjentjs-ts-orm/node';
    
    connect('databaseName', 'username', 'password')
    Note: You can also add a fourth paramter of type sequelize.Options
  4. 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';
    }
  5. Create your object file
    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;
    	}
    }
    Note: The constructor line and injector import are only necessary if you want to use the angular2 connector.
  6. Use the DataConnection object, it should have methods which return promises to your DataContract object
  7. If you want to use foreign key relationships see relationships

Logging

If you need extra logging you can get it one of two ways.

  1. Set DEBUG=ts-orm:* as an environment variable
    • Use DEBUG=ts-orm:*,ts-orm-info:* for more verbose logging
  2. Supply a fifth parameter to connect which conforms to the node.ILogger interface

Clone this wiki locally