cycle-mongoose
v1.1.1
Published
Mongoose.js driver for Cycle.js.
Downloads
2
Maintainers
Readme
Mongoose-cycle
Mongoose.js driver for Cycle.js. Tested and ready.
(Almost) real world example:
import {run} from '@cycle/core'
import {makeMongooseDriver} from '@cycle-drivers/mongoose'
import {from, merge} from 'rx-factory'
const SendVerificationEmails = ({db, emails, schedule}) => {
// pool database every 30 seconds
let dbRequestSchedule$ = schedule.get('*/30 * * * * *').startWith('')
return {
// send emails for found records
emails: db.select('find', _ => _)
.success(found => from(found)).mergeAll()
.map(({email, id}) => ({
id,
to: email,
template: 'verify',
params: {
verifyLink: process.env.VERIFICATION_URL + '/' + id
}
})),
db: merge([
// find verification records not sent
dbRequestSchedule$.map(({
Model: 'Verification',
find: {sent: {$exists: false}}
})),
// update verificaiton record in db after send
emails.success((_, {id}) => ({
Model: 'Verification',
findByIdAndUpdate: [id, {sent: new Date()}]
}))
]),
log: db.select('find', _ => _)
.success(found => `Found ${found.length} verification records to send`)
}
}
run(SendVerificationEmails, {
schedule: scheduleDriver,
emails: emailsDriver,
db: makeMongooseDriver(MONGO_URL, /* connection options */),
log: (message$) => message$.forEach(::console.log)
})
For other query methods see tests.
npm install cycle-mongoose -S