-
Notifications
You must be signed in to change notification settings - Fork 3
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
Diego Garcia
committed
Apr 14, 2019
1 parent
4fddbb7
commit d1baa61
Showing
3 changed files
with
80 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
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,36 @@ | ||
const MongoClient = require('mongodb').MongoClient; | ||
|
||
class LugaresClient { | ||
constructor(db) { | ||
this.db = db; | ||
} | ||
async insert(data) { | ||
try { | ||
if(Array.isArray(data)) { | ||
return await this.db.collection('lugares').insertMany(data); | ||
} | ||
return await this.db.collection('lugares').insertOne(data); | ||
} catch(error) { | ||
throw error; | ||
} | ||
} | ||
async find(query={}) { | ||
try { | ||
return await this.db.collection('lugares').find(query).toArray(); | ||
} catch (error) { | ||
throw error; | ||
} | ||
} | ||
} | ||
|
||
async function getLugaresDBClient() { | ||
try { | ||
const client = new MongoClient(process.env.MONGODB_URI); | ||
await client.connect(); | ||
return new LugaresClient(client.db()); | ||
} catch(error) { | ||
throw error; | ||
} | ||
} | ||
|
||
module.exports = getLugaresDBClient; |
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