Skip to content
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

Result return, Instance of UndecodedBytes for ENUM attributes on DB #276

Open
enzo-desimone opened this issue Jan 10, 2024 · 8 comments
Open

Comments

@enzo-desimone
Copy link

When a query is launched, what is returned for the enumeration attributes in the database is Instance of 'UndecodedBytes'.

@isoos
Copy link
Owner

isoos commented Jan 10, 2024

@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
Copy link
Author

enzo-desimone commented Jan 10, 2024

@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
Screenshot 2024-01-10 183852

@isoos
Copy link
Owner

isoos commented Jan 10, 2024

@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.

@enzo-desimone
Copy link
Author

@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');

@isoos
Copy link
Owner

isoos commented Jan 11, 2024

@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

@ember11498
Copy link

@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

@isoos
Copy link
Owner

isoos commented Feb 1, 2024

@ember11498 for the time being I'd suggest to use the workaround

@ember11498
Copy link

@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();
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants