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

Added support for advanced expressions #32

Merged
merged 26 commits into from
Feb 5, 2025
Merged

Added support for advanced expressions #32

merged 26 commits into from
Feb 5, 2025

Conversation

colodenn
Copy link
Member

@colodenn colodenn commented Jan 28, 2025

This PR introduces support for advanced expressions such as:

number().defaultValue(() => op(5, '-', 3)),
string().check((fields) => op('Hello', '=', fields.stringConcat)),
string().defaultValue(() => sql("UPPER('test')")),
string().computedAs((fields) => ({
  kind: 'VIRTUAL',
  value: op(fields.numberAdd2, '||', fields.numberSubtract),
})),

However, there are still some missing type hints. We want to discourage expressions like:

number().defaultValue(() => op(5, '-', 3))

where database-level expressions are used inside default values. Instead, users should use:

number().defaultValue(() => 5 - 3)

so that the value is evaluated at runtime rather than by the database. This change ensures clearer separation between client-side evaluation and database-generated expressions, improving both type safety and overall code maintainability.

@colodenn colodenn requested a review from leo January 28, 2025 13:21
@colodenn colodenn self-assigned this Jan 28, 2025
Copy link

github-actions bot commented Jan 28, 2025

Released an experimental package:

bun add @ronin/syntax@corny-ron-1099-1-experimental-102

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

@codecov-commenter
Copy link

codecov-commenter commented Feb 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Files with missing lines Coverage Δ
src/schema/model.ts 100.00% <ø> (ø)
src/schema/primitives.ts 100.00% <ø> (ø)
src/utils/expressions.ts 100.00% <100.00%> (ø)

@colodenn colodenn marked this pull request as ready for review February 4, 2025 15:02
leo
leo previously requested changes Feb 4, 2025
@colodenn colodenn requested a review from NuroDev February 4, 2025 16:52
@colodenn colodenn merged commit 9bb34db into main Feb 5, 2025
3 checks passed
@colodenn colodenn deleted the corny/ron-1099-1 branch February 5, 2025 08:38
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.

4 participants