Skip to content
This repository has been archived by the owner on Aug 5, 2021. It is now read-only.

Commit

Permalink
add option disableAutoConnect with connect function
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilWaldmann committed Nov 30, 2017
1 parent c6483c8 commit 219c007
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 9 deletions.
22 changes: 14 additions & 8 deletions lib/stores/ldap/connection.js
Expand Up @@ -8,21 +8,27 @@ exports.store = {
ldapjs: ldap,

mixinCallback: function(){
var self = this
if(!this.config.disableAutoConnect) this.connect()
},

connect: function(){
if(this.connection) this.close()

self.connection = ldap.createClient({
url: self.config.url,
bindDN: self.config.user,
bindCredentials: self.config.password,
maxConnections: self.config.maxConnections || 10,
tlsOptions: self.config.tlsOptions,
reconnect: self.config.reconnect || true
this.connection = ldap.createClient({
url: this.config.url,
bindDN: this.config.user,
bindCredentials: this.config.password,
maxConnections: this.config.maxConnections || 10,
tlsOptions: this.config.tlsOptions,
reconnect: this.config.reconnect || true
})
},

close: function(){
this.connection.unbind()
}


}


Expand Down
5 changes: 5 additions & 0 deletions lib/stores/mysql/connection.js
Expand Up @@ -5,6 +5,11 @@ const Knex = require('knex')
*/
exports.store = {
mixinCallback: function(){
if(!this.config.disableAutoConnect) this.connect()
},

connect: function(){
if(this.connection) this.close()
this.connection = Knex({
dialect: 'mysql',
connection: {
Expand Down
5 changes: 5 additions & 0 deletions lib/stores/oracle/connection.js
Expand Up @@ -5,6 +5,11 @@ var Knex = require('knex')
*/
exports.store = {
mixinCallback: function(){
if(!this.config.disableAutoConnect) this.connect()
},

connect: function(){
if(this.connection) this.close()
this.connection = Knex({
dialect: 'oracledb',
connection: {
Expand Down
5 changes: 5 additions & 0 deletions lib/stores/postgres/connection.js
Expand Up @@ -10,6 +10,10 @@ pg.types.setTypeParser(20, 'text', parseInt)
*/
exports.store = {
mixinCallback: function(){
if(!this.config.disableAutoConnect) this.connect()
},

connect: function(){
var connectionConfig = {
dialect: 'pg',
connection: this.config.connection || {
Expand All @@ -23,6 +27,7 @@ exports.store = {
}
if(this.config.pool) connectionConfig['pool'] = this.config.pool

if(this.connection) this.close()
this.connection = Knex(connectionConfig)
},

Expand Down
9 changes: 9 additions & 0 deletions lib/stores/sqlite3/connection.js
Expand Up @@ -5,12 +5,21 @@ const Knex = require('knex')
*/
exports.store = {
mixinCallback: function(){
if(!this.config.disableAutoConnect) this.connect()
},

connect: function(){
if(this.connection) this.close()
this.connection = Knex({
dialect: 'sqlite3',
connection: {
filename: this.config.file
},
useNullAsDefault: true
})
},

close: function(){

}
}
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "openrecord",
"version": "2.0.0-alpha9",
"version": "2.0.0-alpha10",
"description": "Active record like ORM for nodejs",
"license": "MIT",
"keywords": [
Expand Down

0 comments on commit 219c007

Please sign in to comment.