-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
189 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"_id":"37240c0cb8ab4a7dacd91acaca5fdc5e","nome":"Adriano Waltrick"}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// var npm_diskdb = require('diskdb'); | ||
|
||
function getDbConexoes(npm_diskdb) | ||
{ | ||
var db = npm_diskdb.connect( | ||
'./data/', | ||
['conexoes'] | ||
); | ||
|
||
return db.conexoes; | ||
} | ||
|
||
|
||
module.exports = { | ||
getDbConexoesApp: getDbConexoes | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
function execQuery( | ||
objConexao, | ||
ds_query, | ||
fnCallBackResult | ||
) { | ||
return new Promise( | ||
function (resolve, reject) { | ||
objConexao.connect(); | ||
|
||
objConexao.query( | ||
ds_query, | ||
function (error, arrColunas) { | ||
objConexao.end(); | ||
|
||
if (error){ | ||
reject(error); | ||
return; | ||
} | ||
|
||
resolve( | ||
fnCallBackResult( | ||
arrColunas, | ||
resolve, | ||
reject | ||
) | ||
); | ||
} | ||
); | ||
} | ||
); | ||
} | ||
|
||
function getDatabases(objConexao) { | ||
var ds_query = 'SHOW DATABASES'; | ||
|
||
var fnCallBack = function( | ||
arrValores, | ||
resolve, | ||
reject | ||
) { | ||
var arrDatabases = arrValores.map( | ||
function(objColuna) { | ||
return { | ||
ds_nome : objColuna.Database | ||
}; | ||
} | ||
); | ||
|
||
resolve(arrDatabases); | ||
} | ||
|
||
return execQuery( | ||
objConexao, | ||
ds_query, | ||
fnCallBack | ||
); | ||
} | ||
|
||
module.exports = { | ||
getDatabases: getDatabases | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
var assert = require('assert'); | ||
var npm_db = require('diskdb'); | ||
var chai = require('chai'); | ||
var expect = chai.expect; | ||
|
||
|
||
|
||
describe( | ||
'Teste de diskdb', | ||
function() { | ||
it( | ||
'Remove - save - count', | ||
function (done) { | ||
var db = npm_db.connect( | ||
'./data/', | ||
['collection_test'] | ||
); | ||
|
||
db.collection_test.remove(); | ||
db = null; | ||
|
||
db = npm_db.connect( | ||
'./data/', | ||
['collection_test'] | ||
); | ||
|
||
var objRegistro = { | ||
_id : '0ce47983623f4fb096ab3303d7bb6de7', | ||
nome : 'Adriano Waltrick' | ||
}; | ||
|
||
db.collection_test | ||
.save(objRegistro); | ||
|
||
var arrValor = db.collection_test.find(); | ||
expect(arrValor.length).to.equal(1); | ||
expect(db.collection_test.count()).to.equal(1); | ||
|
||
|
||
done(); | ||
} | ||
); | ||
|
||
it( | ||
'find', | ||
function (done) { | ||
var db = npm_db.connect( | ||
'./data/', | ||
['collection_test'] | ||
); | ||
|
||
var arrValor = db.collection_test.find(); | ||
expect(arrValor.length).to.equal(1); | ||
expect(db.collection_test.count()).to.equal(1); | ||
|
||
done(); | ||
} | ||
); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
var assert = require('assert'); | ||
var npm_mysql = require('mysql'); | ||
|
||
// app | ||
const objMysql = require('../services/mysql.js'); | ||
|
||
describe( | ||
'Teste Servico Mysql', | ||
function() { | ||
describe( | ||
'#getDatabases(objConexao)', | ||
function() { | ||
it( | ||
'Total de databases', | ||
function(done) { | ||
const objConnectionBaseA = npm_mysql.createConnection({ | ||
host : "localhost", | ||
user : "backup", | ||
password : "UniSeguro", | ||
database : "adriano" | ||
}); | ||
|
||
const nr_qtd_database = 18; | ||
|
||
objMysql.getDatabases( | ||
objConnectionBaseA | ||
).then( | ||
function(arrResultadoA) { | ||
var a = assert.equal( | ||
arrResultadoA.length, | ||
nr_qtd_database | ||
); | ||
|
||
var b = assert.equal( | ||
arrResultadoA[0].ds_nome, | ||
'information_schema' | ||
); | ||
|
||
done(); | ||
} | ||
).catch( | ||
function (objError) { | ||
console.log(objError); | ||
} | ||
); | ||
} | ||
); | ||
} | ||
); | ||
} | ||
); |