Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- Test schema-qualified table names
CREATE SCHEMA IF NOT EXISTS app;

CREATE TABLE app.products
(
id SERIAL PRIMARY KEY,
name VARCHAR(128) NOT NULL,
price FLOAT8 NOT NULL
);
27 changes: 27 additions & 0 deletions example-postgres/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,17 @@ struct Test {
rows: Vec<String>,
}

// Example using a schema-qualified table name
#[derive(Debug, ormx::Table)]
#[ormx(table = "app.products", id = id, insertable, deletable)]
struct Product {
#[ormx(default)]
id: i32,
#[ormx(by_ref)]
name: String,
price: f64,
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
dotenv::dotenv().ok();
Expand Down Expand Up @@ -177,5 +188,21 @@ async fn main() -> anyhow::Result<()> {
new.delete(&mut *tx).await?;


info!("test schema-qualified table name (app.products)..");
let product = InsertProduct {
name: "Widget".to_owned(),
price: 19.99,
}
.insert(&mut *tx)
.await?;
info!("inserted product with id {}", product.id);

let fetched = Product::get(&mut *tx, product.id).await?;
info!("fetched product: {:?}", fetched);

product.delete(&mut *tx).await?;
info!("deleted product");


Ok(())
}
8 changes: 7 additions & 1 deletion ormx-macros/src/table/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ impl<B: Backend> Table<B> {

pub fn name(&self) -> String {
let q = B::QUOTE;
format!("{q}{}{q}", self.table)
// Handle schema-qualified table names (e.g., "schema.table")
// by quoting each part separately
self.table
.split('.')
.map(|part| format!("{q}{part}{q}"))
.collect::<Vec<_>>()
.join(".")
}
}

Expand Down