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

Add --readonly-* options #88

Merged
merged 3 commits into from
Oct 29, 2023
Merged

Add --readonly-* options #88

merged 3 commits into from
Oct 29, 2023

Conversation

hasezoey
Copy link
Collaborator

@hasezoey hasezoey commented Oct 9, 2023

This PR adds the options --readonly-prefix and --readonly-suffixes to set a table to be read-only. Read-only means to only generate StructType::Read (not Update or Create) and the corresponding functions.

This is useful for things like SQLite's Views which are read-only (can be read, but cannot be written to)

This PR also includes a slight refactor of the generate_for_table function, which now only adds new-lines and struct if they actually have code, resulting in less empty new-lines (which is more apparent with readonly set)

re #56 --read-only-prefix

Copy link
Owner

@Wulf Wulf left a comment

Choose a reason for hiding this comment

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

Hey, looks good to me (feel free to merge this in) but could you look into why that weird crate::schema::*::Int type was generated instead of i32?

table.set_read_only(true);
}

table
Copy link
Owner

Choose a reason for hiding this comment

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

I think we should have a computation step in the beginning of lib.rs#generate_files() that does some of these pre-generation computations, including aplying the default table options.

Going to create a new issue for this

test/readonly/models/tableSuffix/generated.rs Outdated Show resolved Hide resolved
to set tables to only generate StructType::Read

re Wulf#56
"Int" is not a proper sql type without a number
@hasezoey hasezoey merged commit 78072f8 into Wulf:main Oct 29, 2023
@hasezoey hasezoey deleted the readonly branch October 29, 2023 14:12
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