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: filemanager sea-orm entities #357

Merged
merged 13 commits into from
Jun 26, 2024
Merged

feat: filemanager sea-orm entities #357

merged 13 commits into from
Jun 26, 2024

Conversation

mmalenic
Copy link
Member

Closes #314

Changes

  • Setups up sea-orm entity generation in a build.rs script, and includes the generated code as part of the file manager.
    • A new filemanager-build crate is used for better code organisation.

Leaving this as a draft for now until the phase 1 deployment is complete.

Comment on lines 39 to 43
let generated = quote!(
// Auto-generated by the filemanager build script.
#[path = #path]
pub mod entities;
);
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 required to be able to include the module in the filemanager crate using include!(concat!(env!("OUT_DIR"), "/entities.rs")). My IDE is able to pick up these modules okay, AFAIK vscode should work too.

Comment on lines +57 to +79
/// Create an error with caller location to print error information.
#[track_caller]
fn from(error_kind: ErrorKind) -> Self {
let loc = Location::caller();

if let Some(path) = workspace_path() {
if let Ok(source) = read_to_string(path.join(loc.file())) {
let offset = SourceOffset::from_location(
source.as_str(),
loc.line() as usize,
loc.column() as usize,
);

return Self::new(
error_kind,
Some(NamedSource::new(loc.file(), source)),
Some(offset),
);
}
}

Self::new(error_kind, None, None)
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Using miette for nicer compile/build error printing. #[track_caller] is useful to print line information about where an error occurred, similar to the Rust compiler.

@mmalenic mmalenic added filemanager an issue relating to the filemanager feature New feature labels Jun 24, 2024
Copy link
Member

@brainstorm brainstorm left a comment

Choose a reason for hiding this comment

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

If I understand the code correctly, filemanager-build/src/entities.rs generates ... entities.rs that will be include!-d on mod.rs... for easier source code navigation I would prefix with gen_ or similar (i.e gen_entities.rs), otherwise it gets confusing what codegens what (entities.rs codegenerating another entities.rs somewhere else?) :-S

If filemanager-build/src/entities.rs is the generated file, I'd put a header that states that: Autogenerated file, see the other file gen_entities.rs for its source/generation.

@mmalenic
Copy link
Member Author

That's a good call, filemanager-build/src/entities.rs is not a generated file, it does the generation step. So I think for clarity, I'll rename that to gen_entities.rs. This creates a file called ${OUT_DIR}/entities.rs 🙈 ... That file should have a comment in it, and could be called entities.rs. Or maybe gen.rs so that it's clear where it's included that it represents generated code?

@brainstorm
Copy link
Member

That file should have a comment in it, and could be called entities.rs. Or maybe gen.rs so that it's clear where it's included that it represents generated code?

Either way works, just make it clear which generates and which is generated ;)

@mmalenic mmalenic requested a review from brainstorm June 25, 2024 09:06
Copy link
Member

@victorskl victorskl left a comment

Choose a reason for hiding this comment

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

LGTM!

@mmalenic mmalenic merged commit ba05369 into main Jun 26, 2024
5 checks passed
@mmalenic mmalenic deleted the feat/filemanager branch June 26, 2024 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature filemanager an issue relating to the filemanager
Projects
None yet
Development

Successfully merging this pull request may close these issues.

filemanager: setup sea-orm with entity generation
3 participants