Skip to content

Commit

Permalink
allow using hstore in macros
Browse files Browse the repository at this point in the history
  • Loading branch information
ibotty committed Sep 20, 2024
1 parent a496413 commit 719180e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions sqlx-postgres/src/type_checking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,9 @@ impl_type_checking!(
#[cfg(feature = "time")]
Vec<sqlx::postgres::types::PgRange<sqlx::types::time::OffsetDateTime>> |
&[sqlx::postgres::types::PgRange<sqlx::types::time::OffsetDateTime>],

sqlx::postgres::types::PgHstore,
//Vec<sqlx::postgres::types::PgHstore> | &[sqlx::postgres::types::PgHstore],
},
ParamChecking::Strong,
feature-types: info => info.__type_feature_gate(),
Expand Down
20 changes: 20 additions & 0 deletions tests/postgres/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@ async fn test_query() -> anyhow::Result<()> {
Ok(())
}

#[sqlx_macros::test]
async fn test_hstore() -> anyhow::Result<()> {
let mut conn = new::<Postgres>().await?;

let _ = sqlx::query!(
"INSERT INTO test_hstore(store) VALUES ($1);",
sqlx::postgres::types::PgHstore::from_iter([("key".to_string(), "value".to_string())])
)
.execute(&mut conn)
.await?;

let record = sqlx::query!("SELECT store FROM test_hstore LIMIT 1;")
.fetch_one(&mut conn)
.await?;

assert_eq!(record.store.unwrap()["key"], Some("value".to_string()));

Ok(())
}

#[sqlx_macros::test]
async fn test_non_null() -> anyhow::Result<()> {
let mut conn = new::<Postgres>().await?;
Expand Down
5 changes: 5 additions & 0 deletions tests/postgres/setup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ CREATE EXTENSION IF NOT EXISTS cube;
-- https://www.postgresql.org/docs/current/citext.html
CREATE EXTENSION IF NOT EXISTS citext;

-- https://www.postgresql.org/docs/current/hstore.html
CREATE EXTENSION IF NOT EXISTS hstore;

-- https://www.postgresql.org/docs/current/sql-createtype.html
CREATE TYPE status AS ENUM ('new', 'open', 'closed');

Expand Down Expand Up @@ -58,3 +61,5 @@ CREATE TABLE test_citext (
CREATE SCHEMA IF NOT EXISTS foo;

CREATE TYPE foo."Foo" as ENUM ('Bar', 'Baz');

CREATE TABLE test_hstore(id_test_hstore SERIAL, store HSTORE);

0 comments on commit 719180e

Please sign in to comment.