Skip to content

Commit

Permalink
fix: unwanted raw prepends
Browse files Browse the repository at this point in the history
  • Loading branch information
louisjoecodes committed May 8, 2024
1 parent 9f29c7a commit 944c4b5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
8 changes: 4 additions & 4 deletions js/packages/quary-extension/src/web/commandsImportSources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ export const importSources =
}
const sourcesGenerated = await services.rust.generateSourceFiles({
projectRoot: setupValues.value.projectRoot,
sources: sources.map((source) => ({
name: source.name,
path: source.path,
columns: source.columns.map((column) => column.name),
sources: sources.map(({name, path, columns}) => ({
name,
path,
columns: columns.map((column) => column.name),
})),
folderPath,
})
Expand Down
16 changes: 12 additions & 4 deletions rust/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ async fn main_wrapped() -> Result<(), String> {
Commands::GenerateSources(_) => {
let config = get_config_file(&args.project_file)?;
let database = database_from_config(&config).await?;
let sources = generate_sources(database.as_ref()).await?;
let sources = generate_sources(database.as_ref(), &Some("raw_".to_string())).await?;
let project_file = ProjectFile {
sources,
models: vec![],
Expand Down Expand Up @@ -539,6 +539,7 @@ async fn main_wrapped() -> Result<(), String> {

async fn generate_sources(
database: &dyn DatabaseConnection,
source_name_prefix: &Option<String>,
) -> Result<Vec<ProjectFileSource>, String> {
let tables = database.list_tables().await?;
let views = database.list_views().await?;
Expand All @@ -551,7 +552,7 @@ async fn generate_sources(

Ok(tables_with_columns
.into_iter()
.map(address_to_source)
.map(|address_with_columns| address_to_source(address_with_columns, &source_name_prefix))

Check failure on line 555 in rust/cli/src/main.rs

View workflow job for this annotation

GitHub Actions / Rust Lint

this expression creates a reference which is immediately dereferenced by the compiler
.collect())
}

Expand All @@ -560,9 +561,16 @@ struct AddressWithColumns {
columns: Vec<ColumnWithDetails>,
}

fn address_to_source(address_with_columns: AddressWithColumns) -> ProjectFileSource {
fn address_to_source(
address_with_columns: AddressWithColumns,
source_name_prefix: &Option<String>,
) -> ProjectFileSource {
let source_name = match source_name_prefix {
Some(prefix) => format!("{}{}", prefix, address_with_columns.table.name),
None => address_with_columns.table.name,
};
ProjectFileSource {
name: format!("raw_{}", address_with_columns.table.name),
name: source_name,
tags: vec![],
description: None,
path: address_with_columns.table.full_path,
Expand Down
2 changes: 1 addition & 1 deletion rust/cli/src/rpc_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async fn list_sources(
_: ListSourcesRequest,
database: Box<dyn DatabaseConnection>,
) -> Result<ListSourcesResponse, String> {
let sources = generate_sources(database.as_ref())
let sources = generate_sources(database.as_ref(), &None)
.await
.map_err(|e| format!("Failed to list sources: {}", e))?;
Ok(ListSourcesResponse { sources })
Expand Down

0 comments on commit 944c4b5

Please sign in to comment.