-
Notifications
You must be signed in to change notification settings - Fork 602
feat(postgrest): based select() API to postgrest-js #2083
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
Draft
MildTomato
wants to merge
4
commits into
master
Choose a base branch
from
feat/select-types
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
abcdb13
feat(postgrest): add array-based select() API
MildTomato 579b93b
chore(postgrest): format select-builder files
MildTomato 0d89a38
docs(postgrest): add select-builder implementation plan
MildTomato 643a247
chore(postgrest): format select-builder plan
MildTomato File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| # Plan: Add Array-Based Type-Safe select() API | ||
|
|
||
| ## Overview | ||
|
|
||
| Add a new array-based API for `select()` that provides IDE autocomplete while maintaining full backward compatibility with the existing string-based API. | ||
|
|
||
| ## Design: Hybrid Array API | ||
|
|
||
| Simple cases use strings, complex features use objects: | ||
|
|
||
| ```typescript | ||
| // Simple - just column names | ||
| .select(['id', 'name', 'email']) | ||
|
|
||
| // With alias | ||
| .select(['id', { column: 'username', as: 'display_name' }]) | ||
|
|
||
| // With relation | ||
| .select(['id', { relation: 'posts', select: ['id', 'title'] }]) | ||
|
|
||
| // Complex - all features | ||
| .select([ | ||
| { column: 'created_at', cast: 'text' }, | ||
| { column: 'data', json: ['settings', 'theme'] }, | ||
| { relation: 'posts', hint: 'fk_author', inner: true, select: ['id'] }, | ||
| { spread: true, relation: 'profile', select: ['status'] }, | ||
| { count: true, as: 'total' } | ||
| ]) | ||
| ``` | ||
|
|
||
| ## Type Definitions | ||
|
|
||
| ```typescript | ||
| // Aggregate functions | ||
| type AggregateFunction = 'count' | 'sum' | 'avg' | 'min' | 'max' | ||
|
|
||
| // Field/column selection | ||
| interface FieldSpec { | ||
| column: string | ||
| as?: string | ||
| cast?: string | ||
| json?: string[] | ||
| jsonText?: string[] | ||
| aggregate?: AggregateFunction | ||
| } | ||
|
|
||
| // Relation/join selection | ||
| interface RelationSpec { | ||
| relation: string | ||
| as?: string | ||
| hint?: string | ||
| inner?: boolean | ||
| left?: boolean | ||
| select: SelectSpec | ||
| } | ||
|
|
||
| // Spread operation | ||
| interface SpreadSpec { | ||
| spread: true | ||
| relation: string | ||
| hint?: string | ||
| select: SelectSpec | ||
| } | ||
|
|
||
| // Count shorthand | ||
| interface CountSpec { | ||
| count: true | ||
| as?: string | ||
| cast?: string | ||
| } | ||
|
|
||
| // Single item in select array | ||
| type SelectItem = string | FieldSpec | RelationSpec | SpreadSpec | CountSpec | ||
|
|
||
| // Full select specification | ||
| type SelectSpec = string | SelectItem[] | ||
| ``` | ||
|
|
||
| ## Feature Coverage | ||
|
|
||
| | Feature | String Syntax | Array Syntax | | ||
| | ------------------ | ----------------------- | ----------------------------- | | ||
| | Simple columns | `'id, name'` | `['id', 'name']` | | ||
| | Column alias | `'display:username'` | `{ column, as }` | | ||
| | Type cast | `'col::text'` | `{ column, cast }` | | ||
| | JSON path (->) | `'data->foo'` | `{ column, json: [...] }` | | ||
| | JSON as text (->>) | `'data->>foo'` | `{ column, jsonText: [...] }` | | ||
| | Column aggregate | `'id.sum()'` | `{ column, aggregate }` | | ||
| | Top-level count | `'count()'` | `{ count: true }` | | ||
| | Relation (join) | `'posts(id)'` | `{ relation, select }` | | ||
| | Relation alias | `'author:users(id)'` | `{ relation, as, select }` | | ||
| | Inner join | `'posts!inner(id)'` | `{ relation, inner: true }` | | ||
| | Left join | `'posts!left(id)'` | `{ relation, left: true }` | | ||
| | FK hint | `'users!fk_id(id)'` | `{ relation, hint }` | | ||
| | Spread | `'...profile(status)'` | `{ spread: true, relation }` | | ||
| | Nested relations | `'posts(comments(id))'` | nested `select` arrays | | ||
|
|
||
| ## Files Created/Modified | ||
|
|
||
| ### New Files | ||
|
|
||
| - `src/select-query-parser/select-builder.ts` - Types and serialization | ||
| - `test/select-builder.test.ts` - Unit tests (56 tests) | ||
| - `test/select-builder-integration.test.ts` - Integration tests (24 tests) | ||
| - `test/select-builder.test-d.ts` - Type tests | ||
|
|
||
| ### Modified Files | ||
|
|
||
| - `src/PostgrestQueryBuilder.ts` - Accept array in `select()` | ||
| - `src/PostgrestTransformBuilder.ts` - Accept array in `select()` | ||
| - `src/index.ts` - Export new types | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove this file