anonydb
v2.0.0
Published
This awesome database package was created by Anonydiamond
Downloads
3
Maintainers
Readme
Anony Database
Version 2 update!
What's new:
- Recode (this package is totaly recoded)
- New methods
- Fixed errors
- New way to create database
- Added full type decleartions
- Easy to code
- Complete publication (this package was a
indev
package)
Installation
npm i anonydb
Example:
const Database = require('anonydb')
const db = new Database({
name: 'mydb', //enter database name (where to save)
location: '.' //creates database at current directory (here in package), so it's recommended to enter a full directory name like: C:\users\deskto\todo, If you wanna create database in your desired location. if you wanna create the database inside the package, you only may use '.' as location as it shown here
})
.create() //creates the database
.use() //uses the database
db.set('key', 'value') //sets value to key in database
db.set('todo', 'todo value name here')
console.log(db.get('key')) // Output: value
console.log(db.get('todo')) // Output: todo value name here
console.log(db.get('sdasdasd')) // Output: undefined
How to use methods
| Function | Uses |
-----------|-------
| Use()
| uses the database, if you've already created a database using the create()
function. Then you can use this use()
function. This basically uses or access the the database. If you already have a database created. You only can use: new Database(...).use()
. Don't forget to use this function otherwise you won't be able to access the database |
| Create()
| Creates a database, use it only when you wanna create a database, don't forget to use the use()
function after the database has created. Example: new Database(...).create().use()
|
| Get(k)
| The k
is actually key
. I don't think that i've to say how this works. You should know, as you may used this method in another databases. the key is parameter of value. make sure to use key as string
value. If you wanna get a JSON
value, you can use the JSON.parse(...)
method. To set, use JSON.stringify(...)
, As we use in local storage
|
| Set(k,v)
| You also should know this. You've to enter key:string
at first parameter and value:string
in second paramater. The second parameter type is string
. If you wanna store any json
file. You can use JSON.stringify(...)
method, as you use in localStorage
|
How this database works
The database basically creates folder as you code:
const db = new Database({
name: 'DB' //this the folder name
location: 'C:/users/todo/....' //the location of where the database should be created
})
.create()
.use()
After the database folder has created it uses txt file as every key value. If you name key database key as
ex1
it will createdex1.txt
file, inside the txt file the value will be saved. Example:
db.set('ex1', 'any value here')
db.set('ex2', JSON.stringify({
t: 'test',
your: 'name',
thanks: 'for using the database'
}))
Now the database will save something like this: