@novemberizing/storage
v0.0.33
Published
NOVEMBERIZING STORAGE =====================
Downloads
38
Maintainers
Readme
NOVEMBERIZING STORAGE
"Novemberizing storage" is a library made in JavaScript that allows you to access storage and easily perform tasks such as creating, deleting, and modifying resources.
The goal of "Novemberizing storage" is to support memory, file system, and database as well as various other storage types so that storage can be changed easily by changing the "URL".
The storage class has adapter: Adapter
that executes actual commands and extension: Extension
that can define additional commands as members. For example, in the case of a file system, adapter: Adapter
basically has simple commands such as get()
, set(value)
, del()
to read, write, Only the method that can be deleted is implemented, but if you use extension: ExtensionJson
, you can access the Json file and use a specific key value to define and use methods that can search, modify, or delete with a specific key of the Json
object. .
const o = new Storage({ url: 'fs://./configure.json' });
console.log(o.set("hello.world", {}));
console.log(o.get("hello"));
console.log(o.del("hello"));
INSTALL
The storage library can be installed using "npm".
npm install --save @novemberizing/storage
USAGE
You can create storage objects with URL and execute commands.
const o = new Storage({ url:"fs://./configure.json" });
console.log(o.set("hello", "world"));
console.log(o.get(""));
console.log(o.del("hello"));
USE MEMORY STORAGE
To create and use memory-based storage, simply specify the protocol (mem:
), host, and path in the URL
. In the case of memory-based storage, all values in the storage are initialized when the application is created, and all values are lost when the application is closed. However, if an already created memory storage exists while the application is running, the previously saved value can be used.
const o = new Storage({ url: "mem://./configure.json" });
console.log(o.set("hello", "world"));
console.log(o.get(""));
console.log(o.del("hello"));
USE FILE STORAGE
File storage can be created by specifying the protocol (fs:
), host, and path in URL
just like memory storage. In the case of file storage, unlike memory storage, stored data can be used depending on the existence of a file, independent of application creation and termination.
const o = new Storage({ url: "fs://./configure.json" });
console.log(o.set("hello", "world"));
console.log(o.get(""));
console.log(o.del("hello"));
USE MYSQL DATABASE STORAGE
MYSQL database storage is used by internally creating an adapter that can use the database as a storage. In case of MYSQL database, if you want to use it like a file or memory, you can additionally define and use the extension
setting. You can define and use get
, set
, del
to use it like a JSON memory or file.
const o = new Storage({
url: "mysql://user@localhost:3306/databasename",
adapter: {
password: "password"
},
extension: {
get: { sql: "..." },
set: { sql: "..." },
del: { sql: "..." },
}
});
console.log(o.set("hello", "world"));
console.log(o.get(""));
console.log(o.del("hello"));
USE JSON EXTENSION
You can use the JSON extension by specifying .json
in the file extension. However, in the case of a database, methods such as get(key): object
, set(key, value): object
, del(key): object
must be defined and used.
const fs = new Storage({ url: "fs://./configure.json" });
console.log(fs.set("hello", "world"));
console.log(fs.get(""));
console.log(fs.del("hello"));
const mem = new Storage({ url: "mem://./configure.json" });
console.log(mem.set("hello", "world"));
console.log(mem.get(""));
console.log(mem.del("hello"));
const mysql = new Storage({
url: "mysql://user@localhost:3306/db",
adapter: {
password: "password"
},
extension: {
get: { sql: "..." },
set: { sql: "..." },
del: { sql: "..." },
}
});
console.log(mysql.set("hello", "world"));
console.log(mysql.get(""));
console.log(mysql.del("hello"));