Skip to content

Commit

Permalink
added support v2 aoi.db
Browse files Browse the repository at this point in the history
  • Loading branch information
USERSATOSHI committed Oct 5, 2023
1 parent 73ea61b commit d94160d
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions src/classes/Database.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ class AoijsAPI extends Database {
}

createTable(type) {
if (type === "aoi.db" || type === "default") {
if (!this.extraOptions.dbType) this.extraOptions.dbType = "KeyValue";
if (
type === "aoi.db" ||
type === "default" ||
this.type === "aoi.db-dev"
) {
if (!this.extraOptions.dbType)
this.extraOptions.dbType = "KeyValue";
this.db = new this.module[this.extraOptions.dbType || "KeyValue"]({
path: this.path,
tables: this.tables,
Expand All @@ -81,24 +86,27 @@ class AoijsAPI extends Database {
}

async set(table, name, id, value) {
if (this.type === "aoi.db") {
if (this.type === "aoi.db" || this.type === "aoi.db-dev") {
if (this.extraOptions.dbType === "KeyValue") {

await this.db.set(table, id ? `${name}_${id}` : name, {value});
await this.db.set(table, id ? `${name}_${id}` : name, {
value,
});
} else if (this.extraOptions.dbType === "WideColumn") {
return await this.db.set(
table,
{name: name, value},
{name: "id", value: id},
{ name: name, value },
{ name: "id", value: id },
);
} else if (this.extraOptions.dbType === "Transmitter") {
if (this.extraOptions.dbOptions.databaseType === "KeyValue")
return await this.db.set(table, name, id);
else if (this.extraOptions.dbOptions.databaseType === "WideColumn")
else if (
this.extraOptions.dbOptions.databaseType === "WideColumn"
)
return await this.db.set(
table,
{name: name, value},
{name: "id", value: id},
{ name: name, value },
{ name: "id", value: id },
);
}
} else {
Expand All @@ -107,7 +115,7 @@ class AoijsAPI extends Database {
}

async get(table, name, id) {
if (this.type === "aoi.db") {
if (this.type === "aoi.db" || this.type === "aoi.db-dev") {
if (this.extraOptions.dbType === "KeyValue") {
return await this.db.get(table, id ? `${name}_${id}` : name);
} else if (this.extraOptions.dbType === "WideColumn") {
Expand All @@ -130,13 +138,21 @@ class AoijsAPI extends Database {
(funconId ? this.checkConditionOnId(x, ...funconId) : true),
Infinity,
);
} else {
} else if(this.type === "aoi.db-dev") {
return await this.db.all(table, (x) =>
x.key.startsWith(`${varname}_`) &&
(lengthofId ? x.key.split("_").slice(1).length === lengthofId : true) &&
(funconId ? this.checkConditionOnId(x.key, ...funconId) : true),
Infinity,
);
}
else {
return await super.all(table, varname, lengthofId, funconId);
}
}

async delete(table, name, id) {
if (this.type === "aoi.db") {
if (this.type === "aoi.db" || this.type === "aoi.db-dev") {
return await this.db.delete(table, id ? `${name}_${id}` : name);
} else {
return super.delete(table, name, id);
Expand Down

0 comments on commit d94160d

Please sign in to comment.