Offshore-sql is an adapter for sql databases, created for Offshore
$ npm install offshore-sql$ npm install mysql --save$ npm install mariasql --save$ npm install sqlite3 --save$ npm install pg --saveThis package require installing the oracle instant client and instant client devel downloadable at url :
http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
for rpm linux :
$ su -
# yum localinstall oracle-instantclient12.1-basic-12.1.0.2.0-1.x86_64.rpm# yum localinstall oracle-instantclient12.1-devel-12.1.0.2.0-1.x86_64.rpm# exit
$ vi ~/.bash_profileadd the following lines :
export OCI_LIB_DIR=/usr/lib/oracle/12.1/client64/lib/
export OCI_INCLUDE_DIR=/usr/include/oracle/12.1/client64/
export OCI_VERSION=12
export ORACLE_HOME=/usr/lib/oracle/12.1/client64
export PATH=$PATH:$ORACLE_HOME/bin
export LD_LIBRARY_PATH=$ORACLE_HOME/libsave and exit, then :
$ source~/.bash_profile
$ npm install oracledb --saveConnections are defined by the following attributes :
| Property | Value | Description |
|---|---|---|
dbType | string | Database type (mysql, mariadb, sqlite3, postgres, oracle). |
host | string | Database server host address. |
port | integer | Database server port. |
user | string | Database user. |
password | string | Database user password. |
database | string | Database name. |
adapter | string | Adapter used by this connection. It must correspond to one of the adapters defined before. |
varOffshore=require('offshore');varAdapter=require('offshore-sql');varoffshore=newOffshore();// Define configurationvarconfig={adapters: {// Here we define an adapter name and assign it our adapter module'offshoreAdapter': Adapter},connections: {mySqlConnection: {// adapter is a reference to the adapter name defined aboveadapter: 'offshoreAdapter',host: '127.0.0.1',port: 13306,user: 'root',password: 'itsSecret',database: 'offshoreSql',dbType: 'mysql'}}};// Extend the collectionsvarUser=Offshore.Collection.extend({tableName: 'userTable',identity: 'user',connection: 'mySqlConnection',// Our connection is assigned heremigrate: 'alter',attributes: {id: {columnName: 'ID',type: 'integer',primaryKey: true,unique: true,autoIncrement: true},name: {columnName: "NAME",type: 'string'}}});// Load the collectionsoffshore.loadCollection(User);// Offshore initialization with the config objectoffshore.initialize(config,function(err,ontology){User=ontology.collections.user;// We can now query our model// https://github.com/Atlantis-Software/offshore-docs/blob/master/queries/query-methods.md});MIT © 2016 Atlantis Software & contributors
offshore is free and open-source under the MIT License.