dbdjs.db-sql
v1.0.3
Published
A like package of dbdjs.db with better-sqlite3 wrapper.
Downloads
19
Readme
dbdjs.db-sql
A SQLite version of dbdjs.db, wrapper of better-sqlite3
Table of Contents
Changelog
- Added more Interfaces (Data, AllSQLData).
- Renamed
fetchAll
toall
(README.md). - Added Promised version of class Database for dbd.js
database
compatibility. - Changed returned data format to be the same as dbdjs.db.
About
dbdjs.db-sql is a SQLite version of dbdjs.db, which was a database for dbd.js version 3.0.0+. This package is a wrapper of better-sqlite3, a better version of node-sqlite3. This package was made with TypeScript and was compiled with typescript to JavaScript ES5, which it's JavaScript code was operateable in old browsers ( typescript package explanation ).
Setup
const Package = require("dbdjs.db-sql")
const db = new Package.Database("database.sql", { timeout: 5000 })
API
- new Package.Database(filename: string[, Interfaces.Options]): Database - Initializing Synchronous class Database
- new Package.PromisedDatabase(filename: string[, Interfaces.Options]): Database - Initializing Promised version of class Database
- Database.set(table: string, key: string, value: any): Boolean - Creating/Updating the value of a created/existing data
- Database.get(table: string, key: string): Interfaces.Data | null - Return a data with matching key from the Database
- Database.delete(table:string, key: string): Boolean - Remove a data with matching key from the Database
- Database.all(table: string): Interfaces.AllSQLData[] - Returns an Array of data in the Table
- Database.getTables(): Interfaces.TableInformation[] - Returns an Array of Information about Tables from the Database
- Database.clearTable(table: string): none - Removes the entire data of the Table
- Database.clearDatabase(): Boolean - Removes the entire table from the Database with it's contents
- Database.deleteTable(table: string): none - Remove table from the database
Note: Promised version will return a promise which can be handled using Promises API / Await Asynchronous.
Interfaces
Options ( BetterSqlite3.Options )
- readonly?: boolean - open the database connection in readonly mode (default:
false
). - fileMustExist?: boolean - if the database does not exist, an Error will be thrown instead of creating a new file. This option does not affect in-memory or readonly database connections (default:
false
). - timeout?: number - the number of milliseconds to wait when executing queries on a locked database, before throwing a SQLITE_BUSY error (default:
5000
). - verbose?: function | null - provide a function that gets called with every SQL string executed by the database connection (default:
null
).
Data
- db: Database | PromisedDatabase - The database that is handling SQL
- key: string - The key of data
- value: any - The value of data
AllSQLData
- key: string - The key of data
- data: SQLData - Recevied data information
SQLData
- key: string - The key of data
- value: any - The value of data
TableInformation
- type: string - The type of information
- name: string - The table name
- tbl_name: string - The table name
- rootpage: number
- sql: string - The query which creates the table
License
See LICENSE file in the Github Repository for License.