forrest79 / phpgsql

Simple and fast PHP database library for PostgreSQL with auto converting DB types to PHP and fluent interface for SQL query writing.
Other
11 stars 3 forks source link

Exception - toArray method when enum inside #41

Closed DaveBugg closed 4 months ago

DaveBugg commented 4 months ago

Hey,

After a long time working with MySQL, I've recently started using pgsql and opted for your library. When attempting to retrieve a user row from the table, everything went smoothly:

$a = PGDB::$CONNECT->query('SELECT id, login, access FROM users WHERE token=? LIMIT 1', $token)->fetch();

However, when trying to obtain an array, I encountered an error:

$a = $a->toArray();   // Error: Can't parse type 'users_access' for value 'admin'.

The data type users_access is an enum type, so if I write ('SELECT id, login, access::text .... ), everything works fine. I'm not entirely sure if this is an error, but I thought I'd mention it just in case.

forrest79 commented 4 months ago

Hi, nice to hear that there is a new Postge user :-)

This library is trying to convert all Postgres types to PHP - there is a default data type parser src/Db/DataTypeParsers/Basic.php and this type parser doesn't know the users_access data type. You can extend this data type parser and add this type or if you're OK with parsing this type as a string, casting it as a ::text is also possible.