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

Allow for passing field expressions to indexes #21

Merged
merged 1 commit into from
Nov 11, 2024
Merged

Allow for passing field expressions to indexes #21

merged 1 commit into from
Nov 11, 2024

Conversation

leo
Copy link
Member

@leo leo commented Nov 11, 2024

When creating indexes in SQLite, it's possible to pass expressions in place of specific column names, in which case the expressions will be used to build the index.

For example, instead of indexing on the firstName and lastName columns of an accounts table, you could index on the expression of LOWER("firstName" || ' ' || "lastName"), which would combine both columns into a singular string, lowercase them, and place a space character between them.

This change adds support for expressions in indexes.

@leo leo added the enhancement New feature or request label Nov 11, 2024
@leo leo requested a review from colodenn November 11, 2024 13:37
Copy link

linear bot commented Nov 11, 2024

RON-1083 Improve query compiler further before release

Now that RON-1049 has landed, I am placing my personal list of future improvements for the query transformer on Linear, to prevent it from getting lost as I will begin working on the output transformer.

We have to tackle those improvements before launching the transformer publicly.

  • Ensure that the root export does not allow for passing options. This is currently only the case because the package invokes itself in the case of sub queries. We should have a separate function to accomplish that.
  • Evaluate improved foreign key actions
  • Rename excluding to something that makes it clear that it now acts like SELECT in SQL.
  • Rename to to something that works for both create and set. Previously, create used with, which doesn't make sense, since with allows for asserting fields. to is more accurate since that only allows for providing values. Alternatively, add another instruction that is only used by create, which would also allow us to land RON-503, because set does not need support for arrays at the root level.
  • Consider making group fields use underscores instead of periods, as discussed on Slack.
  • Make sure that "dropping all records of a schema" does not cause a type error.
  • Consider allowing a query to be used as the default value of a field.
  • Consider only requiring slug for schemas, not pluralSlug. Potentially pluralSlug should become the default and be called slug, and then singularSlug could exist for the singular case. Either way, since they are auto-generated, developers should not worry about them in most cases — only if they want to.
  • Consider spreading the error tests in errors.test.ts over the query instruction test files, because meta.test.ts also asserts errors already.
  • Set up a linting rule to avoid duplicate test names, because Bun doesn't seem to complain about this natively, which means we can't know whether we have duplicated test names without checking the whole list of 85 tests manually or with a script for each one.
  • Make including: 'all' work again, but first figure out the syntax. In prod, we support including: 'all', but perhaps we should instead allow globs or a regex so that a list of fields can be matched easily? That could also be used in excluding.
  • Revise all errors one more time to ensure they are consistent.

Open Questions

  • How can people overwrite entire JSON structures? Since, currently, providing an object for a JSON field in a query will perform a json_patch update.
  • Should the default meta field for createdBy and updatedBy be removed, since the accounts are stored in the database of the RONIN space, which is an entirely different database? Perhaps we could handle this by displaying the most recent change event of a record on the dashboard instead, or rather the author of that event.
  • Should we allow for overwriting the createdAt and updatedAt metadata fields?
  • Do we even need zod for validating queries if the transformer already has to validate a lot of things that zod can't do? It almost seems as if the transformer is zod.

Copy link

Released an experimental package:

bun add @ronin/compiler@leo-ron-1083-experimental

This package will be removed after the pull request has been merged.

@leo leo marked this pull request as ready for review November 11, 2024 13:38
@leo leo changed the title Allow for passing column expressions to indexes Allow for passing field expressions to indexes Nov 11, 2024
@leo leo enabled auto-merge (squash) November 11, 2024 13:39
@leo leo merged commit 624ac6f into main Nov 11, 2024
3 checks passed
@leo leo deleted the leo/ron-1083 branch November 11, 2024 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants