Skip to content

Commit

Permalink
add pgvector support (via feature)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkusa committed Mar 14, 2024
1 parent ed11ba4 commit cac5d4b
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion postgres-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ uuid = ["dep:uuid", "postgres/with-uuid-1"]
ariadne = "0.4"
chumsky = "1.0.0-alpha.6"
dotenvy = "0.15"
heck = "0.4"
heck = "0.5"
pgvector = { version = "0.3", features = ["postgres"], optional = true }
postgres = "0.19"
proc-macro2 = { version = "1.0", features = ["span-locations"] }
quote = "1.0"
Expand Down
6 changes: 6 additions & 0 deletions postgres-macros/src/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,12 @@ fn postgres_to_rust_type(
Some((quote!(::uuid::Uuid), quote!(::uuid::Uuid)))
}

// pgvector::Vector
#[cfg(feature = "pgvector")]
ty if <::pgvector::Vector as FromSql>::accepts(ty) => {
Some((quote!(::pgvector::Vector), quote!(::pgvector::Vector)))
}

// Unsupported
_ => None,
}
Expand Down
2 changes: 2 additions & 0 deletions postgres-macros/tests/fail-nightly/enum_extra_variant.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ error[E0277]: the trait bound `Vec<User>: Query<Struct<(StructColumn<i64, "id">,
|
= help: the trait `Query<Struct<(StructColumn<i64, "id">, StructColumn<sqlm_postgres::types::Enum<(EnumVariant<"admin">, EnumVariant<"moderator">, EnumVariant<"user">)>, "role">)>>` is implemented for `Vec<User>`
= note: required for `Sql<'_, Struct<(StructColumn<i64, "id">, StructColumn<Enum<(EnumVariant<"admin">, ...)>, "role">)>, ...>` to implement `IntoFuture`
= note: the full name for the type has been written to '$WORKSPACE/target/tests/trybuild/aarch64-apple-darwin/debug/deps/$CRATE-f72977ab11c336b2.long-type-477280797366746876.txt'
= note: consider using `--verbose` to print the full type name to the console
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ error[E0277]: the trait bound `Vec<User>: Query<Struct<(StructColumn<i64, "id">,
|
= help: the trait `Query<Struct<(StructColumn<i64, "id">, StructColumn<sqlm_postgres::types::Enum<(EnumVariant<"user">,)>, "role">)>>` is implemented for `Vec<User>`
= note: required for `Sql<'_, Struct<(StructColumn<i64, "id">, StructColumn<Enum<(EnumVariant<"admin">, ...)>, "role">)>, ...>` to implement `IntoFuture`
= note: the full name for the type has been written to '$WORKSPACE/target/tests/trybuild/aarch64-apple-darwin/debug/deps/$CRATE-fdec792f290b819a.long-type-8833358810865802699.txt'
= note: consider using `--verbose` to print the full type name to the console
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ error[E0277]: the trait bound `Vec<User>: Query<Struct<(StructColumn<i64, "id">,
|
= help: the trait `Query<Struct<(StructColumn<i64, "id">, StructColumn<sqlm_postgres::types::Enum<(EnumVariant<"moderator">, EnumVariant<"user">)>, "role">)>>` is implemented for `Vec<User>`
= note: required for `Sql<'_, Struct<(StructColumn<i64, "id">, StructColumn<Enum<(EnumVariant<"admin">, ...)>, "role">)>, ...>` to implement `IntoFuture`
= note: the full name for the type has been written to '$WORKSPACE/target/tests/trybuild/aarch64-apple-darwin/debug/deps/$CRATE-c84c4e8ec0844e24.long-type-17999743074283884113.txt'
= note: consider using `--verbose` to print the full type name to the console
4 changes: 3 additions & 1 deletion postgres/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ version = "0.1.0"
edition = "2021"

[features]
default = ["json", "time", "uuid"]
default = ["json", "time", "uuid", "pgvector"]
json = [
"sqlm-postgres-macros/json",
"tokio-postgres/with-serde_json-1",
"dep:serde_json",
]
time = ["sqlm-postgres-macros/time", "tokio-postgres/with-time-0_3", "dep:time"]
uuid = ["sqlm-postgres-macros/uuid", "tokio-postgres/with-uuid-1", "dep:uuid"]
pgvector = ["sqlm-postgres-macros/pgvector", "dep:pgvector"]

[dependencies]
deadpool-postgres = "0.12"
Expand All @@ -20,6 +21,7 @@ http-error = { version = "0.3.0-alpha.1", features = [
"tracing",
] } # git = "https://github.com/rkusa/http-error.git", rev = "1f0630c" } # path = "../../http-error" }
once_cell = "1.17"
pgvector = { version = "0.3", features = ["postgres"], optional = true }
rustls = { version = "0.22" }
serde_json = { version = "1.0", optional = true }
sqlm-postgres-macros = { path = "../postgres-macros", default-features = false }
Expand Down
2 changes: 2 additions & 0 deletions postgres/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ impl_type!(time::OffsetDateTime);
impl_type!(time::Date);
#[cfg(feature = "uuid")]
impl_type!(uuid::Uuid);
#[cfg(feature = "pgvector")]
impl_type!(pgvector::Vector);

impl<'a> SqlType for &'a str {
type Type = String;
Expand Down

0 comments on commit cac5d4b

Please sign in to comment.