presidium-db-client-server 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,7 +26,7 @@ class DiskSortedHashTableClient {
26
26
  this.serverUrl = options.serverUrl
27
27
  this.tableName = options.tableName
28
28
  this.sortValueType = options.sortValueType
29
- this.degree = options.degree ?? 2
29
+ this.degree = options.degree
30
30
  this.delimiter = options.delimiter ?? ""
31
31
  this.http = new HTTP(this.serverUrl)
32
32
  }
@@ -45,8 +45,12 @@ class DiskSortedHashTableClient {
45
45
  const response = await this.http.POST(`/${this.tableName}/clear`, {
46
46
  headers: {
47
47
  "Client-Name": "DiskSortedHashTableClient",
48
- "Sort-Value-Type": this.sortValueType,
49
- "Degree": Number(this.degree),
48
+ ...this.sortValueType ? {
49
+ "Sort-Value-Type": this.sortValueType,
50
+ } : {},
51
+ ...this.degree ? {
52
+ "Degree": Number(this.degree),
53
+ } : {},
50
54
  },
51
55
  })
52
56
  return handleServerResponse(response)
@@ -67,8 +71,12 @@ class DiskSortedHashTableClient {
67
71
  headers: {
68
72
  "Content-Type": "application/json",
69
73
  "Client-Name": "DiskSortedHashTableClient",
70
- "Sort-Value-Type": this.sortValueType,
71
- "Degree": Number(this.degree),
74
+ ...this.sortValueType ? {
75
+ "Sort-Value-Type": this.sortValueType,
76
+ } : {},
77
+ ...this.degree ? {
78
+ "Degree": Number(this.degree),
79
+ } : {},
72
80
  },
73
81
  body: JSON.stringify({ key, value, sortValue }),
74
82
  })
@@ -90,8 +98,12 @@ class DiskSortedHashTableClient {
90
98
  headers: {
91
99
  "Content-Type": "application/json",
92
100
  "Client-Name": "DiskSortedHashTableClient",
93
- "Sort-Value-Type": this.sortValueType,
94
- "Degree": Number(this.degree),
101
+ ...this.sortValueType ? {
102
+ "Sort-Value-Type": this.sortValueType,
103
+ } : {},
104
+ ...this.degree ? {
105
+ "Degree": Number(this.degree),
106
+ } : {},
95
107
  },
96
108
  body: JSON.stringify({ key }),
97
109
  })
@@ -116,8 +128,12 @@ class DiskSortedHashTableClient {
116
128
  headers: {
117
129
  "Content-Type": "application/json",
118
130
  "Client-Name": "DiskSortedHashTableClient",
119
- "Sort-Value-Type": this.sortValueType,
120
- "Degree": Number(this.degree),
131
+ ...this.sortValueType ? {
132
+ "Sort-Value-Type": this.sortValueType,
133
+ } : {},
134
+ ...this.degree ? {
135
+ "Degree": Number(this.degree),
136
+ } : {},
121
137
  },
122
138
  body: JSON.stringify({ key }),
123
139
  })
@@ -143,8 +159,12 @@ class DiskSortedHashTableClient {
143
159
  headers: {
144
160
  "Content-Type": "application/json",
145
161
  "Client-Name": "DiskSortedHashTableClient",
146
- "Sort-Value-Type": this.sortValueType,
147
- "Degree": Number(this.degree),
162
+ ...this.sortValueType ? {
163
+ "Sort-Value-Type": this.sortValueType,
164
+ } : {},
165
+ ...this.degree ? {
166
+ "Degree": Number(this.degree),
167
+ } : {},
148
168
  },
149
169
  body: JSON.stringify(options),
150
170
  })
@@ -179,8 +199,12 @@ class DiskSortedHashTableClient {
179
199
  headers: {
180
200
  "Content-Type": "application/json",
181
201
  "Client-Name": "DiskSortedHashTableClient",
182
- "Sort-Value-Type": this.sortValueType,
183
- "Degree": Number(this.degree),
202
+ ...this.sortValueType ? {
203
+ "Sort-Value-Type": this.sortValueType,
204
+ } : {},
205
+ ...this.degree ? {
206
+ "Degree": Number(this.degree),
207
+ } : {},
184
208
  },
185
209
  body: JSON.stringify(options),
186
210
  })
@@ -215,8 +239,12 @@ class DiskSortedHashTableClient {
215
239
  headers: {
216
240
  "Content-Type": "application/json",
217
241
  "Client-Name": "DiskSortedHashTableClient",
218
- "Sort-Value-Type": this.sortValueType,
219
- "Degree": Number(this.degree),
242
+ ...this.sortValueType ? {
243
+ "Sort-Value-Type": this.sortValueType,
244
+ } : {},
245
+ ...this.degree ? {
246
+ "Degree": Number(this.degree),
247
+ } : {},
220
248
  },
221
249
  body: JSON.stringify(options),
222
250
  })
@@ -252,8 +280,12 @@ class DiskSortedHashTableClient {
252
280
  headers: {
253
281
  "Content-Type": "application/json",
254
282
  "Client-Name": "DiskSortedHashTableClient",
255
- "Sort-Value-Type": this.sortValueType,
256
- "Degree": Number(this.degree),
283
+ ...this.sortValueType ? {
284
+ "Sort-Value-Type": this.sortValueType,
285
+ } : {},
286
+ ...this.degree ? {
287
+ "Degree": Number(this.degree),
288
+ } : {},
257
289
  },
258
290
  body: JSON.stringify(options),
259
291
  })
@@ -289,8 +321,12 @@ class DiskSortedHashTableClient {
289
321
  headers: {
290
322
  "Content-Type": "application/json",
291
323
  "Client-Name": "DiskSortedHashTableClient",
292
- "Sort-Value-Type": this.sortValueType,
293
- "Degree": Number(this.degree),
324
+ ...this.sortValueType ? {
325
+ "Sort-Value-Type": this.sortValueType,
326
+ } : {},
327
+ ...this.degree ? {
328
+ "Degree": Number(this.degree),
329
+ } : {},
294
330
  },
295
331
  body: JSON.stringify({ key }),
296
332
  })
@@ -310,8 +346,12 @@ class DiskSortedHashTableClient {
310
346
  const response = await this.http.POST(`/${this.tableName}/count`, {
311
347
  headers: {
312
348
  "Client-Name": "DiskSortedHashTableClient",
313
- "Sort-Value-Type": this.sortValueType,
314
- "Degree": Number(this.degree),
349
+ ...this.sortValueType ? {
350
+ "Sort-Value-Type": this.sortValueType,
351
+ } : {},
352
+ ...this.degree ? {
353
+ "Degree": Number(this.degree),
354
+ } : {},
315
355
  },
316
356
  })
317
357
  return Number(await handleServerResponse(response))
package/README.md CHANGED
@@ -8,20 +8,41 @@ License: [CFOSS](https://cloutsworld.com/en-us/legal/license/cfoss)
8
8
  [![codecov](https://codecov.io/gh/richytong/presidium-db-client-server/graph/badge.svg?token=07P6G8GIOQ)](https://codecov.io/gh/richytong/presidium-db-client-server)
9
9
  [![npm version](https://img.shields.io/npm/v/presidium-db-client-server.svg?style=flat)](https://www.npmjs.com/package/presidium-db-client-server)
10
10
 
11
- Presidium DB Client and Server. Host your own distributed database.
11
+ Presidium DB Client and Server.
12
12
 
13
+ ## Host your own distributed database
13
14
  ```javascript
14
- const DatabaseServer = require("presidium-db-client-server/DatabaseServer")
15
- const DiskHashTableClient = require("presidium-db-client-server/DiskHashTableClient")
15
+ const DatabaseServer = require("presidium/DatabaseServer")
16
16
 
17
17
  const server = new DatabaseServer({
18
18
  databasePath: `${__dirname}/database`,
19
19
  })
20
20
  await server.init()
21
21
 
22
+ await server.registerDiskHashTable("Session", {
23
+ storagePath: `${this.databasePath}/Session/storage`,
24
+ headerPath: `${this.databasePath}/Session/header`,
25
+ initialLength: 536870912,
26
+ itemSize: 512,
27
+ })
28
+
29
+ await server.registerDiskSortedHashTable("Post", {
30
+ storagePath: `${this.databasePath}/Post/storage`,
31
+ headerPath: `${this.databasePath}/Post/header`,
32
+ initialLength: 1048576,
33
+ itemSize: 8192,
34
+ sortValueType: "number",
35
+ degree: 2,
36
+ })
37
+
22
38
  server.listen(5000, () => {
23
39
  console.log("Database server listening on port 5000")
24
40
  })
41
+ ```
42
+
43
+ ## Call a database table from anywhere
44
+ ```javascript
45
+ const DiskHashTableClient = require("presidium/DiskHashTableClient")
25
46
 
26
47
  const sessionHt = new DiskHashTableClient({
27
48
  serverUrl: "http://localhost:5000",
@@ -38,8 +59,7 @@ const sessionJson = await sessionHt.get(accessToken)
38
59
  await sessionHt.delete(accessToken)
39
60
  ```
40
61
 
41
- Query your distributed database.
42
-
62
+ ## Query a database table from anywhere
43
63
  ```javascript
44
64
  const DiskSortedHashTableClient = require("presidium-db-client-server/DiskSortedHashTableClient")
45
65
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "presidium-db-client-server",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Presidium DB client and server library",
5
5
  "author": "Richard Tong",
6
6
  "license": "CFOSS",