Skip to content

Commit

Permalink
Add Query interface for selecting rows
Browse files Browse the repository at this point in the history
  • Loading branch information
darunrs committed Jul 11, 2024
1 parent 1318cb6 commit 45a2851
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
10 changes: 5 additions & 5 deletions frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ First, download the bos-loader cli by following this guide [here](https://docs.n
From the root of QueryAPI Frontend repo, run the following command

```bash
yarn serve:widgets:local // for running local enviornment
yarn serve:widgets:dev // for running dev enviornment
yarn serve:widgets:prod // for running prod enviornment
npm run serve:widgets:local // for running local enviornment
npm run serve:widgets:dev // for running dev enviornment
npm run serve:widgets:prod // for running prod enviornment
```
> Near.org or any other BOS gateway queries the blockchain state to pull the latest widgets code and renders it. If we would like to test our BOS widgets, we need to override the path at which the gateway (near.org) queries for the widget code. We do this using the Bos-loader tool (the underlying CLI tool used in the `yarn serve:widgets:dev` command) which allows us to serve out widgets locally (http://127.0.0.1:3030 by default). ** This command replaces all keys found in `replacement.dev.json` object with the their values in the widgets directory when serving the widgets **. At this point, we have served our widgets locally but have not yet told the BOS gateway (near.org) where to load our local widgets from.

**Then, Head to `near.org/flags` and enter `http://127.0.0.1:3030`**
**Then, Head to `dev.near.org/flags` and enter `http://127.0.0.1:3030`**

> In order to tell our BOS gateway (near.org), where to load the local widgets from, we head to `near.org/flags` and enter the local path we got from running the previous command. If you have not changed any configurations then the default should be `http://127.0.0.1:3030`
**Finally**, run the following to serve the local NextJS frontend
```bash
yarn dev
npm dev
```

**Now, head to the path where the widgets are served on the BOS.**
Expand Down
2 changes: 1 addition & 1 deletion frontend/replacement.dev.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"REPL_ACCOUNT_ID": "dev-queryapi.dataplatform.near",
"REPL_GRAPHQL_ENDPOINT": "https://near-queryapi.dev.api.pagoda.co",
"REPL_EXTERNAL_APP_URL": "https://queryapi-frontend-vcqilefdcq-ew.a.run.app",
"REPL_EXTERNAL_APP_URL": "http://localhost:3000",
"REPL_REGISTRY_CONTRACT_ID": "dev-queryapi.dataplatform.near"
}
31 changes: 17 additions & 14 deletions frontend/src/utils/pgSchemaTypeGen.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,30 +204,33 @@ export class PgSchemaTypeGen {

tableList.add(sanitizedTableName);

let queryDefinition = `declare interface ${sanitizedTableName}Query {\n`;
let itemDefinition = `declare interface ${sanitizedTableName}Item {\n`;
let inputDefinition = `declare interface ${sanitizedTableName}Input {\n`;

for (const [columnName, columnDetails] of Object.entries(columns)) {
const tsType = columnDetails.nullable ? columnDetails.type + ' | null' : columnDetails.type;
const optional = columnDetails.required ? '' : '?';

queryDefinition += ` ${columnName}?: ${tsType} | ${tsType}[];\n`
itemDefinition += ` ${columnName}?: ${tsType};\n`;
inputDefinition += ` ${columnName}${optional}: ${tsType};\n`;
}

queryDefinition += '}\n\n';
itemDefinition += '}\n\n';
inputDefinition += '}\n\n';
const columnNamesDef = `type ${sanitizedTableName}Columns = "${Object.keys(columns).join('" | "')}";\n\n`;

tsDefinitions += itemDefinition + inputDefinition + columnNamesDef;
tsDefinitions += queryDefinition + itemDefinition + inputDefinition + columnNamesDef;

contextObject += `
${sanitizedTableName}: {
insert: (objectsToInsert: ${sanitizedTableName}Input | ${sanitizedTableName}Input[]) => Promise<${sanitizedTableName}Item[]>;
select: (filterObj: ${sanitizedTableName}Item, limit = null) => Promise<${sanitizedTableName}Item[]>;
update: (filterObj: ${sanitizedTableName}Item, updateObj: ${sanitizedTableName}Item) => Promise<${sanitizedTableName}Item[]>;
select: (filterObj: ${sanitizedTableName}Query, limit = null) => Promise<${sanitizedTableName}Item[]>;
update: (filterObj: ${sanitizedTableName}Query, updateObj: ${sanitizedTableName}Item) => Promise<${sanitizedTableName}Item[]>;
upsert: (objectsToInsert: ${sanitizedTableName}Input | ${sanitizedTableName}Input[], conflictColumns: ${sanitizedTableName}Columns[], updateColumns: ${sanitizedTableName}Columns[]) => Promise<${sanitizedTableName}Item[]>;
delete: (filterObj: ${sanitizedTableName}Item) => Promise<${sanitizedTableName}Item[]>;
delete: (filterObj: ${sanitizedTableName}Query) => Promise<${sanitizedTableName}Item[]>;
},`;
}

Expand Down Expand Up @@ -255,18 +258,18 @@ export class PgSchemaTypeGen {
char: 'string',
text: 'string',
// Binary data types
bytea: 'Buffer',
bytea: 'Buffer | string',
// Boolean type
boolean: 'boolean',
boolean: 'boolean | string',
// Date/Time types
timestamp: 'Date',
'timestamp without time zone': 'Date',
'timestamp with time zone': 'Date',
date: 'Date',
time: 'Date',
'time without time zone': 'Date',
'time with time zone': 'Date',
interval: 'Date',
timestamp: 'Date | string',
'timestamp without time zone': 'Date | string',
'timestamp with time zone': 'Date | string',
date: 'Date | string',
time: 'Date | string',
'time without time zone': 'Date | string',
'time with time zone': 'Date | string',
interval: 'Date | string',
// UUID type
uuid: 'string',
// JSON types
Expand Down

0 comments on commit 45a2851

Please sign in to comment.