Javascript
vanilla javascript
PermaDB also provides a vanilla javascript library to make data management easier.
The vanilla javascript library is based on IndexedDB.
To use the library in the clientside, you first have to import the required script.
To do that, you can add the script tag to your html:
new PermaDB(db_name, [options])
Returns database
By creating a new instance of the PermaDB class, you create and open a new IndexedDB database. You can customize the options of the database with arguments.
db_name
String
The database name to be created. Default is perma.db
.
database
new PermaDB(db_name): database
Database Methods
All methods of PermaDB's javascript library are asynchronous.
set(key, value)
await set(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
get(key)
await get(key): value
Gets the value with the given key in the database.
key String
returns Buffer || String || Date || Number || null
update(key, value)
update(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
delete(key)
delete(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
has(key)
has(key) : exists
Checks if the given key exists in the database. If it does, returns true
. Else returns false
.
key String returns Boolean
type(key)
type(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
all()
all(): [{key, value}]
Gets all key-value pairs in the database inside an array.
returns Array
clear()
clear()
Deletes all key-value pairs in the database.
returns Boolean
removeDB()
removeDB()
Deletes the database after closing it.
returns Boolean
keys()
keys(): [...keys]
Returns the array of the keys
stored in the database.
returns Array
values()
values(): [...values]
Returns the array of the values stored in the database. returns Array
object()
objectSync(): {key: value}
Returns the key-value pairs as a Javascript Object.
returns Object
length()
length(): length
Gets the number of existing key-value pairs in the database. returns Boolean
Last updated