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

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft

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-89

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

onDelete?: 'CASCADE' | 'SET NULL' | 'SET DEFAULT' | 'NO ACTION';
onUpdate?: 'CASCADE' | 'SET NULL' | 'SET DEFAULT' | 'NO ACTION';
};
} & ModelFieldExpressions<TypeToTSType<Type>>
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a temporary solution and will be changed in a followup PR.

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