🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

dbd.db-alternative

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dbd.db-alternative

Allows users to use dbd.db functions with Known/Custom Databases

latest
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

dbd.db-alternative

Allows users to use dbd.db functions with Known/Custom Databases

Currently Supports

  • Mongoose (MongoDB) (Promise based)
  • MySQL (Promise based)
  • Better-Sqlite3 (Static)

Note: More database will be added, soon or later.

Supported Methods

  • set(data, filter) - Creates/Modify a data/row in the Database/Table
  • find(filter, limit) - Collects datas/rows from the Database/Table
  • findOne(filter) - Collects a data/row from the Database/Table
  • delete(filter, limit) - Deletes limit (Default is Infinity) amount of data/row in the Database/Table (Below is only for SQLite Database)
  • createTable(tableName, SchemaQuery) - Creates and Uses a table in the SQLite database with provided Schema, does not overwrite existing ones
  • useTable(tableName) - Use an existing table in the SQLite database (for better-sqlite3 is the same with createTable)

Note: Promise based database will need Promises to completely executed or return data, Others can be coded normally.

Examples

These Databases requires their own Dependency, you can find the npm package above.

More detailed examples can be found in the Examples Folder

Mongoose

  • new (Package).mongoose(MongooseModel)

Start up

// make sure to install mongoose
const dbdDbAlternative = require("dbd.db-alternative")
const mongoose = require("mongoose")

mongoose.connect(Mongoose URL..., MongooseOptions...)
const MongooseConnection = mongoose.connection 
MongooseConnection.on("open", () => {
  console.log("Connected to Mongoose Database!")
})

const mongodb = new dbdDbAlternative.mongoose(MongooseModel)
// now you can use `mongodb` like dbd.db functions

MongooseModel

const mongoose = require("mongoose")
const Schema = mongoose.Schema 
const mySchema = new Schema(MongooseSchemaDocuments...)
const myModel = mongoose.model("mySchema", mySchema)
// import myModel to be used as MongooseModel

MySQL

  • new (Package).mysql(MySQLConnection)

Start up

// make sure to install mysql
const dbdDbAlternative = require("dbd.db-alternative")
const MySql = require("mysql")
// This example is to connect to Localhost mysql 
// But you can use other Hosting Provider
// As MySQL Database
const MySqlConnection = MySql.createConnection({
    host:"localhost",
    user:"root",
    database:"mydatabase"
})

MySqlConnection.connect()
const mysql = new dbdDbAlternative.mysql(MySqlConnection)

// Create Tables
const table = mysql.createTable("myTable", `
username TEXT,
id INTEGER PRIMARY KEY
`)

// Schema Column types can be found in https://www.sqlite.org/datatype3.html

// Use Tables 
mysql.useTable("myTable")
.then(table => {
  //do something with `table`
})
.catch(error) => {
  //do something with `error`
}

Better Sqlite 3

  • new (Package).betterSqlite3(Path | Absolute Path | Filename)

Start up

// make sure to install better-sqlite3
const dbdDbAlternative = require("dbd.db-alternative")
const betterSqlite3 = new dbdDbAlternative.betterSqlite3("database.sqlite"[, better-sqlite3 options])
// WARNING, DO NOT USE FORMATS THAT ARE GLOBAL KNOWN/USED FOR PROGRAMMING, USE CUSTOM FORMATS.

//Creating and Using Table (createTable and useTable) is the same with `createTable`
const table = betterSqlite3.createTable("myTable", `
username TEXT,
id INTEGER PRIMARY KEY
`)

// Schema Column types can be found in https://www.sqlite.org/datatype3.html

// do something with `table`

License

See Mit License or License File for License.

Copyright 2021 DBD.JS Team

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

dbd.js

FAQs

Package last updated on 09 Mar 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts