Last active
February 11, 2020 16:02
-
-
Save albovieira/51e93198da414f13daf4bb1539d5d3bb to your computer and use it in GitHub Desktop.
exemplo.js
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
function createMongoDB() { | |
return DatabaseFactory.create({ | |
type: 'mongodb', | |
database: 'test-package', | |
url: 'mongodb://localhost:27017', | |
options: { | |
reconnectInterval: 1000, | |
useNewUrlParser: true | |
} | |
}); | |
} | |
function createMySQLDB() { | |
return DatabaseFactory.create({ | |
type: 'mysql', | |
database: 'db', | |
url: 'localhost', | |
options: { | |
user: 'test', | |
password: 'test' | |
} | |
}); | |
} | |
const database = createMySQLDB(); | |
// const database = createMongoDB(); | |
// ex, indenpendente se for mysql ou mongo | |
const result = await database.insert({ | |
collection: 'user', | |
data: { | |
name: 'Albo', | |
position: 'midfielder' | |
} | |
}); | |
const result = await database.get({ | |
collection: 'user', | |
conditions: [ | |
{ | |
field: 'name', | |
value: 'Albo', | |
operator: 'eq' | |
} | |
] | |
}); | |
// raw para o caso de mysql | |
const result = await database.execRaw(`SELECT * FROM user`, { | |
collection: 'user' | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment