Skip to content

Commit

Permalink
Removed clean table names from SDK to have the logic on the OrbisDB i…
Browse files Browse the repository at this point in the history
…nstance instead
  • Loading branch information
baptistegreve committed Jan 25, 2024
1 parent 9e8ccca commit 4f2ba7e
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 33 deletions.
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@useorbis/db-sdk",
"version": "0.0.9-alpha",
"version": "0.0.11-alpha",
"description": "Orbis' Typescript SDK for building open-data experiences.",
"keywords": [
"web3",
Expand Down
5 changes: 0 additions & 5 deletions src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,9 @@ export class OrbisNode {

// Add a method to get the model ID for a human-readable table name
getTableModelId(tableName: string): string | undefined {
console.log("Enter getTableModelId with:", tableName);
const modelsMapping = this.node?.metadata?.models_mapping;
console.log("modelsMapping:", modelsMapping);
for (const [id, name] of Object.entries(modelsMapping || {})) {
if (name === tableName) {
console.log("Found table:");
console.log("id:", id);
console.log("name:", name);
return id;
}
}
Expand Down
27 changes: 0 additions & 27 deletions src/querybuilder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,32 +81,6 @@ export class QueryBuilder {
node?: string | number
): Promise<StatementExecuteResult> {

// Update table name on select to convert it to the actual model id
if(this.isSelectStatement(query)) {
let modelId;
const tableName = (query as any)._single.table; // Get the table name from the query
console.log("tableName:", tableName);
// Check if developer used directly a model id or a readable table name
if(tableName.startsWith("kjzl6")) {
modelId = tableName;
} else {
// Get the model ID mapped to this table name in instance settings
modelId = this.#orbis.node.getTableModelId(tableName);
console.log("modelId retrieved from getTableModelId is:", modelId);

// Force retry to load node's metadata to retrieve latest mapping and try again
if(!modelId) {
console.log("Couldn't retrieve modelId for this table name, retrying...");
await this.#orbis.node.metadata();
console.log("Forced reload the node's metadata.");
modelId = this.#orbis.node.getTableModelId(tableName);
console.log("After retry, modelId is:", modelId);;
}
}
// Set the table to model ID
(query as any)._single.table = modelId;
}

if ("statementType" in query) {
if (query.statementType === "CERAMIC_INSERT" && "document" in query) {
const document = await query.document();
Expand Down Expand Up @@ -159,7 +133,6 @@ export class QueryBuilder {
}

const { sql, bindings: params } = query.toSQL().toNative();

return this.#orbis.node.query(sql, params as Array<any>);
}

Expand Down

0 comments on commit 4f2ba7e

Please sign in to comment.