Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support WHERE col IN (...) in context.db.table.select and delete #606

Merged
merged 8 commits into from
Mar 19, 2024

Conversation

pkudinov
Copy link
Collaborator

@pkudinov pkudinov commented Mar 18, 2024

With this PR, we can use context.db.Table.select({column_name: ['a.near', 'b.near']}). I think it is best to keep it within the same select method instead of introducing a new one like selectMany. The same support is added for delete.

Frontend support is added. I also improved parameter naming to reflect SQL statements like where, values and set. Here is the sample output:

declare interface ActionsIndexItem {
  block_date: Date;
  receiver_id: string;
  first_block_height: number;
  bitmap: string;
}

declare interface ActionsIndexPartial {
  block_date?: Date;
  receiver_id?: string;
  first_block_height?: number;
  bitmap?: string;
}

declare interface ActionsIndexFilter {
  block_date?: Date | Date[];
  receiver_id?: string | string[];
  first_block_height?: number | number[];
  bitmap?: string | string[];
}

type ActionsIndexColumns = "block_date" | "receiver_id" | "first_block_height" | "bitmap";

declare const context: {
	graphql: (operation, variables) => Promise<any>,
	set: (key, value) => Promise<any>,
	log: (...log) => Promise<any>,
	fetchFromSocialApi: (path, options) => Promise<Response>,
	db: {
		ActionsIndex: {
			insert: (values: ActionsIndexItem | ActionsIndexItem[]) => Promise<ActionsIndexItem[]>;
			select: (where: ActionsIndexFilter, limit = null) => Promise<ActionsIndexItem[]>;
			update: (where: ActionsIndexPartial, set: ActionsIndexPartial) => Promise<ActionsIndexItem[]>;
			upsert: (values: ActionsIndexItem | ActionsIndexItem[], conflictColumns: ActionsIndexColumns[], updateColumns: ActionsIndexColumns[]) => Promise<ActionsIndexItem[]>;
			delete: (where: ActionsIndexFilter) => Promise<ActionsIndexItem[]>;
		},
  }
};

@pkudinov pkudinov requested a review from a team as a code owner March 18, 2024 21:34
Copy link
Collaborator

@darunrs darunrs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Nice changes!

@darunrs
Copy link
Collaborator

darunrs commented Mar 18, 2024

Let me check if the frontend allows for this too.

@darunrs
Copy link
Collaborator

darunrs commented Mar 18, 2024

Yeah it will not. Let me suggest the frontend fix to allow this...

@darunrs
Copy link
Collaborator

darunrs commented Mar 18, 2024

let tsTypeBase = columnDetails.type + " | " + columnDetails.type + "[]";
let tsType = columnDetails.nullable ? tsTypeBase + " | null" : tsTypeBase;

https://github.com/near/queryapi/blob/main/frontend/src/utils/pgSchemaTypeGen.js#L172

@pkudinov pkudinov changed the title Support WHERE col IN (...) in context.db.table.select Support WHERE col IN (...) in context.db.table.select and delete Mar 19, 2024
Copy link
Collaborator

@darunrs darunrs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small comments. Otherwise, it seems to work! I tried it out in the frontend and ran a simple indexer in the backend that does selects and deletes and observed the right behavior.

frontend/src/utils/pgSchemaTypeGen.js Outdated Show resolved Hide resolved
frontend/src/utils/pgSchemaTypeGen.js Outdated Show resolved Hide resolved
@pkudinov pkudinov merged commit d814879 into main Mar 19, 2024
5 checks passed
@pkudinov pkudinov deleted the feat/where-in branch March 19, 2024 19:03
@darunrs darunrs mentioned this pull request Mar 28, 2024
darunrs added a commit that referenced this pull request Apr 3, 2024
- feat: Instrument Runner Service (#602)
- Support WHERE col IN (...) in context.db.table.select and delete
(#606)
- feat: Include indexer name in context db build failure warning (#611)
- Cache provisioning status (#607)
- Fix ESLint on DmlHandler (#612)
- fix: Substitution 'node-sql-parser' with a forked version until Apri
1st (#597)
- feat: Add pgBouncer to QueryApi (#615)
- feat: Expose near-lake-primitives to VM (#613)

---------

Co-authored-by: Pavel Kudinov <mrkroz@gmail.com>
Co-authored-by: Pavel Kudinov <pavel@near.org>
Co-authored-by: Kevin Zhang <42101107+Kevin101Zhang@users.noreply.github.com>
Co-authored-by: Morgan McCauley <morgan@mccauley.co.nz>
This was referenced Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants