@ryanforever/database
v3.0.0
Published
a simple database to get you up and running running fast. uses mongoose.
Downloads
1
Readme
database
simple mongoose/mongoDB client
quick setup
Use this way to just get your schemas setup quickly. you cannot add statics or methods using this way.
const Database = require("@ryanforever/database")
const database = new Database({
username: process.env.USERNAME,
password: process.env.PASSWORD,
url: process.env.URL,
collection: process.env.COLLECTION
})
// add schema
// you cant add statics or methods using this way
let User = database.addSchema("User", {
name: String,
verified: Boolean
})
User.find({verified: true}).then(console.log)
advanced usage
Using this way, you can add statics and methods
const Database = require("@ryanforever/database")
const database = new Database({
username: process.env.USERNAME,
password: process.env.PASSWORD,
url: process.env.URL,
collection: process.env.COLLECTION
})
// create a schema
let userSchema = new database.Schema({
name: {type: String, unique: true},
birthday: Date,
verified: Boolean
})
// (OPTIONAL) add statics/methods
userSchema.statics.getVerified = async function() {
return await this.find({verified: true})
}
// add it to the model
let User = database.model("User", userSchema)
// do stuff
User.create({
name: "john smith",
verified: false
}).then(console.log)