Open enzo-desimone opened 10 months ago
@enzo-desimone: if you have a reproduction case (either a single SELECT or a CREATE/INSERT/SELECT), I can look into how hard is to add better support.
@enzo-desimone: if you have a reproduction case (either a single SELECT or a CREATE/INSERT/SELECT), I can look into how hard is to add better support.
Thanks for response @isoos
Query execute
final res = await PostgresDB.connection.execute(
Sql.named('SELECT * from portfolio WHERE pathname=@pathname ORDER BY t1.id ASC'),
parameters: conditions,
);
print(res);
Print result
[[11, Instance of 'UndecodedBytes', /wizzy]]
Database enum
@enzo-desimone: I don't have information about your portfolio
table. Please provide a SELECT that is self-contained, or a CREATE/INSERT/SELECT pair.
@isoos, here you are:
PORTFOLIO TABLE
CREATE TABLE IF NOT EXISTS public.portfolio_item
(
id integer NOT NULL DEFAULT nextval('portfolio_item_portfolio_item_id_seq'::regclass),
category item_category NOT NULL,
pathname character varying COLLATE pg_catalog."default" NOT NULL,
CONSTRAINT portfolio_item_pkey PRIMARY KEY (id),
CONSTRAINT unique_link_path UNIQUE (pathname)
)
ITEM_CATEGORY ENUM
CREATE TYPE public.item_category AS ENUM
('android', 'blackberry', 'flutter');
@enzo-desimone: this is a custom type, and we don't have typed support for it yet. However, I've created a test to provide an example on how you can access the string content of the unknown bytes: https://github.com/isoos/postgresql-dart/pull/278/files
@isoos I have read your workaround. I am just wondering when result.first.toColumnMap() will support enum, meaning the custom enum varables being represented as the strings instead of Instance of 'UndecodedBytes'. Wondering if I should bother doing the work around or if i should just wait, Thanks in advance
@ember11498 for the time being I'd suggest to use the workaround
@isoos I just wrote an extension on Result that works prety well.
import 'package:postgres/postgres.dart';
extension ResultExtensions on Result {
List<Map<String, dynamic>> get tableToMap {
return map((row) {
return row.toColumnMap().map((key, value) {
if (value is UndecodedBytes) {
return MapEntry(key, (value).asString);
} else {
return MapEntry(key, value);
}
});
}).toList();
}
}
When a query is launched, what is returned for the enumeration attributes in the database is
Instance of 'UndecodedBytes'
.