-
Notifications
You must be signed in to change notification settings - Fork 119
Connecting to DB
Omar Sharim edited this page Jun 3, 2015
·
17 revisions
-
object config: can contain any of the following optional properties
-
string driver:
- default value:
null
- adapter to use when connecting to database server
- default value:
-
string user:
- default value:
process.env.USER
- Database user
- default value:
-
string database:
- default value:
process.env.USER
- database to use when connecting to database server
- default value:
-
string password:
- default value:
null
- user's password for database server
- default value:
-
number port:
- default value:
depends by adapter
- port to use when connecting to database server
- default value:
-
string host:
- default value:
null
- host address of database server
- used to initialize underlying net.Stream()
- default value:
-
bool pool:
- default value:
false
- used pooling connections to connect to server
- default value:
-
bool ssl:
- default value:
false
- whether to try SSL/TLS to connect to server
- default value:
-
string driver:
First, we need to define a connection.
For MySQL database need install mysql client. Then:
$ npm install mysql --save
var caminte = require('caminte'),
Schema = caminte.Schema,
config = {
driver : "mysql", // mariadb
host : "localhost",
port : "3306",
username : "test",
password : "test",
database : "test",
pool : true // optional for use pool directly
};
var schema = new Schema(config.driver, config);
For SQLite database need install sqlite3 client. Then:
$ npm install sqlite3 --save
var caminte = require('caminte'),
Schema = caminte.Schema,
config = {
driver : "sqlite3",
database : "/db/mySite.db"
};
var schema = new Schema(config.driver, config);
For PostgreSQL database need install postgres client. Then:
$ npm install pg --save
var caminte = require('caminte'),
Schema = caminte.Schema,
config = {
driver : "postgres",
host : "localhost",
port : "5432",
username : "test",
password : "test",
database : "test",
pool : true // optional for use pool directly
};
var schema = new Schema(config.driver, config);
For Redis database need install redis client. Then:
$ npm install redis --save
var caminte = require('caminte'),
Schema = caminte.Schema,
config = {
driver : "redis",
host : "localhost",
port : "6379"
};
var schema = new Schema(config.driver, config);