3.0.0 • Published 1 year ago

@ryanforever/database v3.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

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)
2.0.2

1 year ago

3.0.0

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.2

2 years ago

1.0.0

2 years ago