chuckpreslar / codex

SQL Relational Algebra for Go.
76 stars 7 forks source link

Add visitor for bytea/BLOB types? #35

Open drbawb opened 11 years ago

drbawb commented 11 years ago

A possible enhancement for inserts & updates.


When passing a Go value of type []byte to codex through Insert() or Set() it returns the error: No visitor method for <[]uint8>. after calling ToSql()

I know the lib/pq driver for Postgres natively supports passing []bytes as a paramater for columns of type bytea, and I imagine most other databases would support this as a BLOB though I don't know how their Go driver's handle it.

chuckpreslar commented 11 years ago

Haven't made my way around to working with SQL BLOB types yet, now that you've opened this I'll get on it.

drbawb commented 11 years ago

Thanks. I was actually just looking at Arel's visitors and I don't see that they handle BLOB's either. Which makes sense as I'm not sure there's a portable syntax for inserting BLOBs.

At least for Postgres: you could possibly encode the []byte to a string of hex characters in codex, and then emit SQL to use Postgres' built in decode() function to have the database transform the varchar back into a bytea. e.g: (decode('0a0b0c0d0e0f', 'hex'))