dbd.db-alternative

0.0.2 • Public • Published

dbd.db-alternative

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

Currently Supports

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.

Dependencies (4)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i dbd.db-alternative

    Weekly Downloads

    5

    Version

    0.0.2

    License

    MIT

    Unpacked Size

    24.7 kB

    Total Files

    10

    Last publish

    Collaborators

    • kino-leref-abandoned-child