Skip to content

Instantly share code, notes, and snippets.

@albovieira
Last active February 11, 2020 16:02
Show Gist options
  • Save albovieira/51e93198da414f13daf4bb1539d5d3bb to your computer and use it in GitHub Desktop.
Save albovieira/51e93198da414f13daf4bb1539d5d3bb to your computer and use it in GitHub Desktop.
exemplo.js
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