Node.js
Documentation for the npm package 'perma.db'
Last updated
Documentation for the npm package 'perma.db'
Last updated
PermaDB is a versatile and easy to use database management library that aims to be fast, and save space.
Importing the class from the module.
Returns
By creating a new instance of the PermaDB class, you create and open a new sqlite3 database. You can customize the options of the database with arguments.
db_name
String
The database name to be created. Default is perma.db
.
options
Object
memory Boolean
options.memory
specifies if the db works both with the database file and on memory. Default is false
.
minimize Boolean
options.minimize
specifies if the db will automatically perform vacuum operations. Default is false
.
preload Boolean
options.preload
specifies if all database should be loaded to the memory. Only considered if the options.memory
is true
. Default is false
.
Creating the instance of class PermaDB imported from perma.db.
new PermaDB(db_name, [options]): database
setSync(key, value): value
Stores the value in the database, so you can access it with the key after.
key String
value Buffer || String || Date || Number || null
returns Buffer || String || Date || Number || null
getSync(key): value
Gets the value with the given key in the database.
key String
returns Buffer || String || Date || Number || null
fetchSync(key): value
Gets the value with the given key in the database.
returns Buffer || String || Date || Number || null
key String returns Buffer || String || Date || Number || null
updateSync(key, value): changed
If the given key exists in the database, changes its value and returns true
. If it doesn't exist, returns false
.
key String
value Buffer || String || Date || Number || null returns Boolean
hasSync(key) : exists
Checks if the given key exists in the database. If it does, returns true
. Else returns false
.
key String returns Boolean
deleteSync(key): success
Checks if the given key exists in the database. If it does, deletes it and returns true
. Else returns false
.
key String
returns Boolean
removeSync(key): success
Checks if the given key exists in the database. If it does, deletes it and returns true
. Else returns false
.
key String
returns Boolean
typeSync(key): typeof value
Checks if the given key exists in the database. If it does, returns the type of the value. Else returns null
.
key String returns String
allSync(): [{key, value}]
Gets all key-value pairs in the database inside an array.
returns Array
fetchAllSync(): [{key, value}]
Returns all key-value pairs in the database inside an array.
returns Array
deleteAllSync(): success
Deletes all key-value pairs in the database.
returns Boolean
removeAllSync(): success
Deletes all key-value pairs in the database.
returns Boolean
clearSync(): success
Deletes all key-value pairs in the database.
returns Boolean
deleteDBSync(): success
Unlinks(removes) the database after closing it.
returns Boolean
removeDBSync(): success
Unlinks(removes) the database after closing it.
returns Boolean
vacuumSync(): success
Executes SQLite 'Vacuum' command on the database. returns Boolean
backupSync(path): success
Closes the database. If the path already exists, returns false. If it doesn't, creates a backup.
path String
returns Boolean
querySync(sql, ...params): results
Execute an sql query.
sql String
params Any returns Any
sizeSync(): size
Get the total size of the database contents.
returns Number
fileSizeSync(): filesize
Get the file size of the database SQLite file.
returns Number
keysSync(): [...keys]
Returns the array from the keys of the database.
returns Array
valuesSync(): [...values]
Returns the array of the values stored in the database. returns Array
objectSync(): {key: value}
Returns the key-value pairs as a Javascript Object.
returns Object
execSync(cmd): output
Executes the given SQLite command, and returns the output.
cmd String
returns String?
closeSync(): success
Closes the database. returns Boolean
expireSync(key, time): success
Waits for the given time(ms). If exists, deletes the given key along with it's value from the database, and returns true
. Else returns false
.
returns Boolean
lengthSync(): length
Gets the number of existing key-value pairs in the database. returns Boolean
async set(key, value): Promise<Buffer || String || Date || Number || null>
Stores the value in the database, so you can access it with the key after. Returns a promise which resolves with the value.
key String
value Buffer || String || Date || Number || null
async get(key): Promise<value || null>
Returns a promise which resolves with the value for the given key in the database
key String
async fetch(key): value || null
Stores the value in the database, so you can access it with the key after. Returns a promise which resolves with the value.
key String
async update(key, value) : Promise<true || false>
If the given key exists in the database, changes its value and resolves with true
. If it doesn't exist, resolves false
.
key String
value Buffer || String || Date || Number || null
async has(key) : Promise<true || false>
Checks if the given key exists in the database. If it does, resolves with true
. Else resolves false
.
key String
async delete(key): Promise<true || false>
Checks if the given key exists in the database. If it does, deletes it and returns true
. Else returns false
.
key String
remove(key): Promise<true || false>
Checks if the given key exists in the database. If it does, deletes it and returns true
. Else returns false
.
key String
async type(key): Promise<typeof value || null>
Checks if the given key exists in the database. If it does, returns the type of the value. Else returns null
.
key String
async all(): Promise<[{key, value}]>
Resolves all key-value pairs in the database inside an array.
async fetchAll(): Promise<Array [{key, value}]>
Returns all key-value pairs in the database inside an array.
async deleteAll(): Promise<true>
Deletes all key-value pairs in the database, and returns true
async removeAll(): Promise<true>
Deletes all key-value pairs in the database, and returns true
async clear(): Promise<true>
Deletes all key-value pairs in the database, and returns true
async deleteDB(): Promise<true>
Unlinks(removes) the database after closing it and returns true
.
async removeDB(): Promise<true>
Unlinks(removes) the database after closing it and returns true
.
async vacuum(): Promise<true>
Vacuums the database and returns true
.
async backup(path): Promise<true || false>
Closes the database. If the path already exists, returns false. If it doesn't, creates a backup.
path String
async query(sql, ...params): Promise<results>
Execute an sql query.
sql String
params Any
async size(): Promise<Number || null>
Returns the total size of the database contents.
async fileSize(): Promise<Number>
Resolves with the database file size in bytes
async keys(): Promise<Array [keys]>
Resolves with the array from the keys of the database.
async values(): Promise<Array [values(Buffer || String || Date || Number || null)]>
Resolves with the array of database values
async object(): Promise<{key, value} (Object)>
Resolves with key-value pairs as a Javascript Object.
async exec(cmd): Promise<output(String)>
Executes the given sqlite command, and returns the output.
cmd String
async close(): Promise<true>
Closes the database and resolves with true.
async expire(key, time): Promise<success>
If exists, deletes the given key along with it's value from the database, and returns true
.
Else returns false
.
key String
time Number
resolves with Boolean
length(): Promise<Number>
Resolves with the number of existing key-value pairs in the database.
Defined in
Defined in
Defined in
Defined in
Defined in
Defined in
Defined in
Defined in
Defined in
Defined in
Defined in
Defined in
Defined in
Defined in
Defined in
Defined in
Defined in
Defined in
Defined in
Defined in
Defined in
Defined in
Defined in
Defined in
Defined in
Defined in
Defined in