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
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)
MongooseModel
const mongoose = require("mongoose")
const Schema = mongoose.Schema
const mySchema = new Schema(MongooseSchemaDocuments...)
const myModel = mongoose.model("mySchema", mySchema)
MySQL
- new (Package).mysql(MySQLConnection)
Start up
const dbdDbAlternative = require("dbd.db-alternative")
const MySql = require("mysql")
const MySqlConnection = MySql.createConnection({
host:"localhost",
user:"root",
database:"mydatabase"
})
MySqlConnection.connect()
const mysql = new dbdDbAlternative.mysql(MySqlConnection)
const table = mysql.createTable("myTable", `
username TEXT,
id INTEGER PRIMARY KEY
`)
mysql.useTable("myTable")
.then(table => {
})
.catch(error) => {
}
Better Sqlite 3
- new (Package).betterSqlite3(Path | Absolute Path | Filename)
Start up
const dbdDbAlternative = require("dbd.db-alternative")
const betterSqlite3 = new dbdDbAlternative.betterSqlite3("database.sqlite"[, better-sqlite3 options])
const table = betterSqlite3.createTable("myTable", `
username TEXT,
id INTEGER PRIMARY KEY
`)
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.