presidium-db-client-server
v4.3.2
Published
Presidium DB client and server
Maintainers
Readme
Presidium DB Client and Server

Source code: GitHub | License: CFOSS
Presidium DB client and server.
Host your own distributed database
const DatabaseServer = require("presidium/DatabaseServer")
const server = new DatabaseServer({
databasePath: `${__dirname}/database`,
})
await server.init()
await server.registerDiskHashTable("Session", {
storagePath: `${this.databasePath}/Session/storage`,
headerPath: `${this.databasePath}/Session/header`,
initialLength: 536870912,
itemSize: 512,
})
await server.registerDiskSortedHashTable("Post", {
storagePath: `${this.databasePath}/Post/storage`,
headerPath: `${this.databasePath}/Post/header`,
initialLength: 1048576,
itemSize: 8192,
sortValueType: "number",
degree: 2,
})
server.listen(5000, () => {
console.log("Database server listening on port 5000")
})Call a database table from anywhere
const DiskHashTableClient = require("presidium/DiskHashTableClient")
const sessionHt = new DiskHashTableClient({
serverUrl: "http://localhost:5000",
tableName: "Session",
})
const accessToken = "token"
const session = { accessToken }
await sessionHt.set(accessToken, JSON.stringify(session))
const sessionJson = await sessionHt.get(accessToken)
await sessionHt.delete(accessToken)Query a database table from anywhere
const DiskSortedHashTableClient = require("presidium-db-client-server/DiskSortedHashTableClient")
const postHt = new DiskSortedHashTableClient({
serverUrl: "http://localhost:5000",
tableName: "Post",
sortValueType: ["string", "number"],
})
const post1 = {
id: "post-1",
profileId: "profile-1",
images: ["/assets/post-1/image-1.jpg"],
content: "First post",
time: Date.now(),
}
const post2 = {
id: "post-2",
profileId: "profile-1",
images: ["/assets/post-2/image-2.jpg"],
content: "Second post",
time: Date.now(),
}
const post3 = {
id: "post-3",
profileId: "profile-1",
images: ["/assets/post-3/image-3.jpg"],
content: "Third post",
time: Date.now(),
}
await postHt.set(post1.id, JSON.stringify(post1), "profile-1", post1.time)
await postHt.set(post2.id, JSON.stringify(post2), "profile-1", post2.time)
await postHt.set(post3.id, JSON.stringify(post3), "profile-1", post3.time)
const myPosts = []
for await (const postJson of postHt.reverseIterator({
startingSortValue: ["profile-1", Infinity],
endingSortValue: ["profile-1", 0],
})) {
myPosts.push(JSON.parse(postJson))
}Load balance your distributed database
const DatabaseLoadBalancer = require("presidium/DatabaseLoadBalancer")
const loadBalancer = new DatabaseLoadBalancer({
serverIps: ["10.0.0.1:8080", "10.0.0.2:8080"],
})
loadBalancer.listen(6333, () => {
console.log("Database load balancer listening on port 6333")
})Installation
with npm:
npm i presidium-db-client-serverLicense
Presidium DB Client and Server is distributed under the CFOSS License.
Support
- minimum Node.js version: 16
