|
1 | 1 | # jsonVerse
|
2 | 2 |
|
3 |
| -jsonVerse is a lightweight JSON-based database package for Node.js. It provides a simple interface to store, retrieve, and manage data using JSON files. |
| 3 | +## Deprecated |
4 | 4 |
|
5 |
| -[](https://github.com/Marco5dev/jsonverse/actions/workflows/code-test.yml) |
6 |
| -[](https://github.com/Marco5dev/jsonverse/actions/workflows/npm-publish.yml) |
7 |
| -[](https://www.npmjs.com/package/jsonverse) |
8 |
| -[](https://www.npmjs.com/package/jsonverse) |
9 |
| -[](https://github.com/Marco5dev/jsonverse) |
10 |
| -[](https://github.com/Marco5dev/jsonverse/blob/master/LICENSE) |
11 |
| -[](https://github.com/Marco5dev/jsonverse/graphs/contributors) |
12 |
| -[](https://github.com/Marco5dev/jsonverse/commits/master) |
| 5 | +# Moved to verse.db |
13 | 6 |
|
14 |
| -## Introduction |
15 |
| - |
16 |
| -The jsonVerse package is a powerful utility designed to simplify the management of JSON data files within a designated folder. It offers methods for adding, editing, deleting, and retrieving data from JSON files. This wiki provides detailed examples and usage scenarios to help you effectively implement the jsonVerse package in your projects. |
17 |
| - |
18 |
| -## Installation |
19 |
| - |
20 |
| -To begin using the jsonVerse package, you'll need to install it via npm. Open your terminal and run the following command: |
21 |
| - |
22 |
| -```bash |
23 |
| -npm install jsonverse |
24 |
| -``` |
25 |
| - |
26 |
| -## Usage |
27 |
| - |
28 |
| -### Import and Initialization |
29 |
| - |
30 |
| -To get started, import the required modules, set up an Express router, and initialize the jsonVerse instance: |
31 |
| - |
32 |
| -```javascript |
33 |
| -const express = require("express"); |
34 |
| -const app = express(); |
35 |
| -const jsonverse = require("jsonverse"); |
36 |
| - |
37 |
| -// Initialize the JSONDatabase instance |
38 |
| -const db = new jsonverse({ |
39 |
| - dataFolderPath: "./MyData", // data directory |
40 |
| - logFolderPath: "./MyLogs", // logs directory |
41 |
| - activateLogs: true, // to enable the logs set this value to true |
42 |
| -}); |
43 |
| -``` |
44 |
| - |
45 |
| -### Display All Data |
46 |
| - |
47 |
| -You can display all the data from your website using the following code: |
48 |
| - |
49 |
| -```javascript |
50 |
| -app.get("/", async (req, res) => { |
51 |
| - try { |
52 |
| - const allData = await db.allData(); |
53 |
| - // ... (rendering logic) |
54 |
| - } catch (err) { |
55 |
| - // ... (error handling) |
56 |
| - } |
57 |
| -}); |
58 |
| -``` |
59 |
| - |
60 |
| -### Display Data from a specific data json file |
61 |
| - |
62 |
| -you can display data from a specific data file by file name |
63 |
| - |
64 |
| -```javascript |
65 |
| -app.get("/", async (req, res) => { |
66 |
| - try { |
67 |
| - db.readData(dataName) // dataName: the name of the json file like test.json the data name will be "test" |
68 |
| - .then((result) => { |
69 |
| - res.send(result); // result is the content of the json file |
70 |
| - }) |
71 |
| - .catch((err) => { |
72 |
| - console.log(err); |
73 |
| - }); |
74 |
| - } catch (err) { |
75 |
| - // ... (error handling) |
76 |
| - } |
77 |
| -}); |
78 |
| -``` |
79 |
| - |
80 |
| -### Add Data |
81 |
| - |
82 |
| -To add data, use the following code: |
83 |
| - |
84 |
| -```javascript |
85 |
| -app.post("/add", async (req, res) => { |
86 |
| - try { |
87 |
| - const { dataName, name, social, rank, competition, date, edu, password } = |
88 |
| - req.body; |
89 |
| - const newData = { |
90 |
| - social, |
91 |
| - name, |
92 |
| - rank, |
93 |
| - competition, |
94 |
| - date, |
95 |
| - edu, |
96 |
| - password: db.encrypt(password, "Your-Secret-Key"), |
97 |
| - }; |
98 |
| - await db.saveData(dataName, newData); |
99 |
| - // ... (redirect or response) |
100 |
| - } catch (err) { |
101 |
| - // ... (error handling) |
102 |
| - } |
103 |
| -}); |
104 |
| -``` |
105 |
| - |
106 |
| -### Get Data by ID |
107 |
| - |
108 |
| -Retrieve data by its ID with this code: |
109 |
| - |
110 |
| -```javascript |
111 |
| -app.get("/:id", async (req, res) => { |
112 |
| - const id = req.params.id; |
113 |
| - try { |
114 |
| - const result = await db.findById(id); |
115 |
| - if (result) { |
116 |
| - // ... (rendering logic) |
117 |
| - // remember if the retrieved data contained encrypted data to use |
118 |
| - // db.decrypt(encryptedData, secretKey) |
119 |
| - } else { |
120 |
| - // ... (not found logic) |
121 |
| - } |
122 |
| - } catch (err) { |
123 |
| - // ... (error handling) |
124 |
| - } |
125 |
| -}); |
126 |
| -``` |
127 |
| - |
128 |
| -### Delete Data by ID |
129 |
| - |
130 |
| -Delete data by its ID using this code: |
131 |
| - |
132 |
| -```javascript |
133 |
| -app.delete("/:id", async (req, res) => { |
134 |
| - const id = req.params.id; |
135 |
| - try { |
136 |
| - await db.delById(id); |
137 |
| - // ... (response or redirect) |
138 |
| - } catch (err) { |
139 |
| - // ... (error handling) |
140 |
| - } |
141 |
| -}); |
142 |
| -``` |
143 |
| - |
144 |
| -### Edit Data by ID |
145 |
| - |
146 |
| -Edit existing data using this code: |
147 |
| - |
148 |
| -```javascript |
149 |
| -app.post("/edit/:id", async (req, res) => { |
150 |
| - const id = req.params.id; |
151 |
| - const { name, social, rank, competition, date, edu } = req.body; |
152 |
| - try { |
153 |
| - const updatedData = { |
154 |
| - social, |
155 |
| - name, |
156 |
| - rank, |
157 |
| - competition, |
158 |
| - date, |
159 |
| - edu, |
160 |
| - }; |
161 |
| - await db.editById(id, updatedData); |
162 |
| - // ... (response or redirect) |
163 |
| - } catch (err) { |
164 |
| - // ... (error handling) |
165 |
| - } |
166 |
| -}); |
167 |
| -``` |
168 |
| - |
169 |
| -### Encrypt/Decrypt |
170 |
| - |
171 |
| -you can encrypt/decrypt the data that you are saving by this commend |
172 |
| - |
173 |
| -- Encrypt |
174 |
| - |
175 |
| -```javascript |
176 |
| -db.encrypt(data, secretKey); |
177 |
| -``` |
178 |
| - |
179 |
| -- Decrypt |
180 |
| - |
181 |
| -```javascript |
182 |
| -db.decrypt(encryptedData, secretKey); |
183 |
| -``` |
184 |
| - |
185 |
| -### Backup |
186 |
| - |
187 |
| -backup the data files you want by the dataName in Backup folder in Data Folder (the package create it automatically) |
188 |
| - |
189 |
| -```javascript |
190 |
| -db.backupCreate(dataName); // dataName: the name of the data file you want to backup |
191 |
| -``` |
192 |
| - |
193 |
| -### Restore Backup |
194 |
| - |
195 |
| -Restore the backup data files you want by the dataName in Backup `./Data/Backup` ./Data is the path you add to the data folder |
196 |
| - |
197 |
| -```javascript |
198 |
| -db.backupRestore(dataName, backupFileName); // the dataName is the data you want to restore to it & the backupFileName is the backup file name you got after backing up |
199 |
| -``` |
200 |
| - |
201 |
| -### Delete Backup |
202 |
| - |
203 |
| -Delete the backup data json files you want by the dataName in Backup folder in Data Folder (the package create it automatically) |
204 |
| - |
205 |
| -```javascript |
206 |
| -const retentionDays = 5; // write here with days the time you want to delete the backups since then like i want to delete the backup the had been saved the last 5 days |
207 |
| -db.backupDelete(dataName, retentionDays); |
208 |
| -``` |
209 |
| - |
210 |
| -### Import/Export Data |
211 |
| - |
212 |
| -- Import |
213 |
| - |
214 |
| -you can import data from json files from outside the project files |
215 |
| - |
216 |
| -```javascript |
217 |
| -db.importData(dataName, (format = "json"), filePath); |
218 |
| -// dataName: the data file you want to import to if exist if doesn't write the new data name instead |
219 |
| -// format: to set the format to json you don't need to write it it's json by default |
220 |
| -// filePath: where is the file you want to import |
221 |
| -``` |
222 |
| - |
223 |
| -- Export |
224 |
| - |
225 |
| -you can Export data from json files |
226 |
| - |
227 |
| -```javascript |
228 |
| -db.exportData(dataName, (format = "json")); |
229 |
| -// dataName: the data file you want to Export |
230 |
| -// format: to set the format of the new exported file like json and csv |
| 7 | +```console |
| 8 | +npm i verse.db |
231 | 9 | ```
|
232 | 10 |
|
233 |
| -## Conclusion |
234 |
| - |
235 |
| -The jsonVerse package simplifies the management of JSON data files within a specified folder. With the provided examples and usage instructions, you'll be able to efficiently integrate the jsonVerse package into your projects to streamline data operations. |
| 11 | +> - Docs: |
| 12 | +https://versedb.jedi-studio.com |
0 commit comments