Created
July 9, 2018 19:55
-
-
Save pablohpsilva/a8a5df1bae91b48d67fce61846063e3c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
// Ideia de uso: | |
const fmongo = FunctionalMongo('mongodb://0.0.0.0:27017/yhub') | |
.collect('User') | |
.byId({ id }) | |
*/ | |
import { curry, objOf } from 'ramda' | |
import { MongoClient } from 'mongodb' | |
const _connect = curry((uri, options = { useNewUrlParser: true }) => MongoClient.connect(uri, options)) | |
const _collection = curry((connection, collectionName) => connection.collection(collectionName)) | |
const _FunctionalMongo = async (uri, options) => { | |
const client = await _connect(uri, options); | |
const connection = client.db(); | |
return objOf( | |
'collect', | |
(collectionName) => { | |
const collection = await _collection(connection, collectionName) | |
return objOf( | |
'byId', | |
(identifier) => collection.find(identifier) | |
) | |
} | |
) | |
} | |
export default curry(_FunctionalMongo) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment