dbx icon indicating copy to clipboard operation
dbx copied to clipboard

support custom field types

Open egonelbre opened this issue 2 years ago • 4 comments

Currently there's significant amount of code that's being written to convert from []byte to uuid.UUID, because dbx doesn't seem to allow specifying custom types.

egonelbre avatar Sep 07 '23 14:09 egonelbre

this would be great. an easy but janky way to do it is to require that the type not have any .s in it (because the parsing is harder) and allow any type for the field and use aliases. for example, just allow field foo uuid and add a type uuid = uuidpkg.UUID into the package somewhere.

i think the code gen needs to know how to create a zero value, but actually it could always have done *new(T) for any T like we do with generics now.

zeebo avatar Sep 08 '23 14:09 zeebo

Maybe:

model baz (
	field id bytea ( default 50, type "storj.io/common/uuid.UUID" )
)

But, this should work as well, most of the time

model baz (
	field id bytea ( default 50, type storj.io/common/uuid.UUID )
)

egonelbre avatar Sep 08 '23 14:09 egonelbre

One option would be to allow specifying custom types,e.g.

type StorjUUID (
    sqlite   text
    postgres bytea
    go       storj.io/common/uuid.UUID
)

model baz (
	field id StorjUUID ( default 50 )
)

egonelbre avatar Sep 08 '23 14:09 egonelbre

i think the quoted version would be easiest to support with the current parser. also, this works nicely as long as conversions are applicable, but uuid is a special case where it isn't.. more info or a convention is required for handling non-convertable types.

and your go directive in the type means this is a bit more complicated than i thought. maybe it's time to just drop hypothetical other languages as a feature because it hasn't materialized in 7 years lol.

zeebo avatar Sep 08 '23 15:09 zeebo