istreamdata / orientgo

Go (golang) client for OrientDB
MIT License
125 stars 22 forks source link

Support for custom types (UUID, etc) #52

Open oharlem opened 8 years ago

oharlem commented 8 years ago

Hi,

I'm using Cassandra with OrientDB in one system and have to handle uuid<->string conversions throughout the app having to store as a string in OrientDB, while using native uuid/timeuuid in Cassandra. It would be great to be able to use actual UUID type with queries, not a string value.

Currently:

  1. There's an error if I'm trying to bind a UUID value, ex. ...Command(orient.NewSQLCommand(INSERT INTO Users SET userID = ?, p.UserID))
  2. Workaround is to convert to a string manually: ....Command(orient.NewSQLCommand(INSERT INTO Users SET userID = ?, p.UserID.String()))
  3. On reading from a query, need to read as a string value and then to parse into UUID again, ex. uuid.Parse(uuidStr).

Thank you, D.

dennwc commented 8 years ago

Hi @mpmlj ,

For case 3 you can use RegisterMapDecoderHook to provide function that can converts strings to UUID type (or vice versa). This will help to decode Documents to maps/structs with UUID. Still, Documents itself will contain raw string values.

For case 1-2 I think the right way will be to allow conversion to string via TextMarshaler interface. Does the package you are using provides implementation for this interface?