Closed isaacharrisholt closed 1 month ago
Good idea. I'm not sure what the API might be though 🤔
Honestly pgo.enum(String)
is probably best, and users can have their own custom type -> string functions if they want them
That may require us to generate atoms at runtime, which doesn't seems great. We'll need to look at what PGO does internally.
I can't seem to replicate the issue, enums work totally fine from my experiments:
create type mood as enum ('sad', 'ok', 'happy');
create table moods (
current_mood mood primary key
);
let assert Ok(pgo.Returned(1, [])) =
"insert into moods values ($1)"
|> pgo.execute(db, [pgo.text("happy")], dynamic.dynamic)
let assert Ok(pgo.Returned(1, ["happy"])) =
"select current_mood from moods"
|> pgo.execute(db, [], dynamic.element(0, dynamic.string))
let assert Ok(pgo.Returned(1, ["happy"])) =
"select current_mood from moods where current_mood = $1"
|> pgo.execute(db, [dynamic.text("happy")], dynamic.element(0, dynamic.string))
They're always treated as strings, both when used as query params or appear in the returned values
Hooray!
Hallo, I'd like to be able to insert Postgres enums with PGO. I've tried inserting them as text to no avail by doing something like: