-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
unsupported type ResourceKind for param #2 #2149
Comments
#1171 1171 |
But in your case you should be able to do
to get it to work |
I'm running into this same error but I'm not sure it's related to #1171. My enum is defined inside the same schema as the rest of the database. CREATE TYPE "role" AS ENUM (
'user',
'manager',
'admin'
);
CREATE TABLE "users" (
"id" BIGINT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
"username" VARCHAR NOT NULL UNIQUE,
"first_name" VARCHAR,
"middle_name" VARCHAR,
"last_name" VARCHAR,
"email" VARCHAR NOT NULL UNIQUE,
"role" role NOT NULL,
"active" BOOLEAN NOT NULL,
"password_hash" VARCHAR
); In my code I have: #[derive(Debug, Default, Clone, Serialize, Deserialize, Type, PartialEq, Eq)]
#[sqlx(rename_all = "snake_case")]
#[sqlx(type_name = "role")]
#[serde(rename_all = "snake_case")]
pub enum Role {
#[default]
User,
Manager,
Admin,
}
#[derive(Debug, Default, Serialize, Deserialize, FromRow)]
pub struct User {
#[serde(skip_deserializing)]
pub id: i64,
pub username: String,
pub first_name: Option<String>,
pub middle_name: Option<String>,
pub last_name: Option<String>,
pub email: String,
pub role: Role,
pub active: bool,
password_hash: Option<String>,
}
impl User {
async fn get_by_username(pool: &PgPool, username: String) -> Result<Self, sqlx::Error> {
sqlx::query_as!(Self, "SELECT * FROM users WHERE username = $1", username)
.fetch_one(pool)
.await
}
} Which raises the error:
The only way around this is the much more verbose: async fn get_by_username(pool: &PgPool, username: String) -> Result<Self, sqlx::Error> {
sqlx::query_as!(
Self,
r#"
SELECT
id,
username,
first_name,
middle_name,
last_name,
email,
role as "role: Role",
active,
password_hash
FROM users WHERE username = $1
"#,
username
)
.fetch_one(pool)
.await
} |
@abonander maybe close it as #2149 (comment) solves it ? |
I am confusing about why when using template data, the |
Bug Description
my table
it tell me
how can i insert a postgres enum type?
The text was updated successfully, but these errors were encountered: