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

feat: chain queries #78

Merged
merged 2 commits into from
Jan 31, 2024
Merged

Conversation

friendlymatthew
Copy link
Collaborator

Query Chaining

Query chaining is more fluent and flexible in its query style.

You can now write queries:

const query = await db
  .where('trip_distance', '>=', 10)
  .orderBy('trip_distance', 'ASC')
  .select([
      'VendorID',
      'trip_distance',
      'passenger_count',
      'fare_amount',
      'tip_amount',
      'mta_tax'
  ])
  .get();

It's forkable, so you can write derived queries:

const query = await db.where("...");
const derivedQuery = query.orderBy("...");

This PR also introduces a JS editor to the demo. The editor can now toggle between JSON and JS. Depending on the editor, you can build a query in JSON form or through the chaining of clauses.

Since the demo's gotten a lot more features, I also separated the .css and the editor-related logic to its own files.

Copy link
Owner

@kevmo314 kevmo314 left a comment

Choose a reason for hiding this comment

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

Nice!

src/db/query-builder.ts Outdated Show resolved Hide resolved
@friendlymatthew friendlymatthew merged commit df96d76 into kevmo314:main Jan 31, 2024
2 checks passed
kevmo314 pushed a commit that referenced this pull request Feb 5, 2024
* feat: chain queries

* refactor
kevmo314 added a commit that referenced this pull request Feb 5, 2024
* feat: switch to b+ tree

* fixes

* init: csv handler

* coverage: recognize null fields test

* fix: ci

* pass tests

* Add `selectFields` to query language (#71)

* add support fields

* rename + convert to Pick type

* CSV demo + support null fields (#67)

* support csv, account for null

* cleanup + refactor csv + include jsonl

* cleanup + direct workflow to csv

* Add CSV table (#74)

* add csv table

* change to ternary exp

* Add query validation to library (#77)

* add query validation

* refactor

* feat: chain queries (#78)

* feat: chain queries

* refactor

* Coverage: Assert query chain behavior (#79)

* coverage

* memory conservation

---------

Co-authored-by: Matthew <[email protected]>
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