Socket
Socket
Sign inDemoInstall

quickmongo

Package Overview
Dependencies
115
Maintainers
4
Versions
34
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.7 to 3.0.0

8

package.json
{
"name": "quickmongo",
"version": "2.0.7",
"version": "3.0.0",
"description": "Quick mongodb wrapper for beginners.",

@@ -27,3 +27,3 @@ "main": "index.js",

"author": "Snowflake107",
"license": "Apache License 2.0",
"license": "Apache-2.0",
"bugs": {

@@ -53,3 +53,7 @@ "url": "https://github.com/DevSnowflake/quickmongo/issues"

"discord.js-docgen": "github:discordjs/docgen"
},
"directories": {
"doc": "docs",
"test": "test"
}
}

@@ -16,3 +16,3 @@ # QuickMongo

- Key value based
- Beginner friendly
- Simple
- Asynchronous

@@ -19,0 +19,0 @@ - Multiple model support

@@ -21,4 +21,4 @@ const EventEmitter = require("events").EventEmitter;

/**
* @typedef {string} dbURL
* Current database url
* @type {string}
*/

@@ -35,8 +35,12 @@ Object.defineProperty(this, "dbURL", {

this._create();
/**
* Returns mongodb connection
* @type {MongooseConnection}
*/
this.connection = this._create();
mongoose.connection.on("error", (e) => {
this.connection.on("error", (e) => {
this.emit("error", e);
});
mongoose.connection.on("open", () => {
this.connection.on("open", () => {
/**

@@ -53,15 +57,14 @@ * Timestamp when database became ready

* Creates mongodb connection
* @returns {MongooseConnection}
* @ignore
*/
_create(url) {
// do not create multiple connections
if (this.state === "CONNECTED" || this.state === "CONNECTING") return;
this.emit("debug", "Creating database connection...");
if (url && typeof url === "string") {
this.dbURL = url;
};
if (url && typeof url === "string") this.dbURL = url;
if (!this.dbURL || typeof this.dbURL !== "string") throw new Error("Database url was not provided!", "MongoError");
delete this.options["useUnique"];
mongoose.connect(this.dbURL, {
return mongoose.createConnection(this.dbURL, {
...this.options,

@@ -79,3 +82,3 @@ useNewUrlParser: true,

_destroyDatabase() {
mongoose.disconnect();
this.connection.close(true);
this.readyAt = undefined;

@@ -85,10 +88,2 @@ this.dbURL = null;

}
/**
* Returns mongodb connection
* @type {MongooseConnection}
*/
get connection() {
return mongoose.connection;
}

@@ -105,6 +100,7 @@ /**

* Returns database connection state
* @type {"DISCONNECTED"|"CONNECTED"|"CONNECTING"|"DISCONNECTING"}
* @type {("DISCONNECTED"|"CONNECTED"|"CONNECTING"|"DISCONNECTING")}
*/
get state() {
switch(mongoose.connection.readyState) {
if (!this.connection || typeof this.connection.readyStaet !== "number") return "DISCONNECTED";
switch(this.connection.readyState) {
case 0:

@@ -111,0 +107,0 @@ return "DISCONNECTED";

@@ -14,5 +14,5 @@ const Base = require("./Base");

* Creates quickmongo instance
* @param {string} mongodbURL Mongodb database url
* @param {string} name Model name
* @param {object} connectionOptions Mongoose connection options
* @param {string} [mongodbURL] Mongodb database url
* @param {string} [name] Model name
* @param {object} [connectionOptions] Mongoose connection options
* @example const { Database } = require("quickmongo");

@@ -28,3 +28,3 @@ * const db = new Database("mongodb://localhost/quickmongo");

*/
this.schema = Schema(name);
this.schema = Schema(this.connection, name);
}

@@ -295,3 +295,3 @@

/**
* Returns database uptime
* Returns database connection uptime
* @type {number}

@@ -298,0 +298,0 @@ * @example console.log(`Database is up for ${db.uptime} ms.`);

@@ -1,2 +0,2 @@

const { Schema, model } = require("mongoose");
const { Schema } = require("mongoose");

@@ -15,4 +15,4 @@ const Default = new Schema({

module.exports = (name) => {
return typeof name === "string" ? model(name, Default) : model("JSON", Default);
module.exports = (connection, name) => {
return typeof name === "string" ? connection.model(name, Default) : connection.model("JSON", Default);
};

@@ -22,2 +22,3 @@ declare module "quickmongo" {

public readyAt: Date;
public connection: Mongoose.Connection;

@@ -29,6 +30,5 @@ constructor(

private _create(url: string): Promise<void>;
private _create(url?: string): Promise<Mongoose.Connection>;
private _destroyDatabase(): Promise<void>;
public get url(): string;
public get connection(): Mongoose.Connection;
public get state(): "CONNECTED" | "CONNECTING" | "DISCONNECTED" | "DISCONNECTING";

@@ -93,3 +93,3 @@

constructor(
mongodbURL: string,
mongodbURL?: string,
name?: string,

@@ -96,0 +96,0 @@ connectionOptions?: Mongoose.ConnectionOptions

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc