Open EtienneBruines opened 1 year ago
This would make using SurrealDB pretty straight forward.
I'd like to help out if possible. Anything I can pick up?
I've been playing around with this and I noticed a couple of things:
FETCH
support for returned objects/structs
type fetch[T any] []T
func (yne fetch[T]) Scan(value any) error { if value == nil { yne = fetch[T]{} return nil }
bytes, err := json.Marshal(value)
if err != nil {
return err
}
items := fetch[T]{}
err = json.Unmarshal(bytes, &items)
if err != nil {
return err
}
*yne = append(*yne, items...)
return nil
}
2. the fields dont necessarily come back in order, this will be kinda difficult to wrangle when it is time to Scan the data into the values. edit: I just noticed that the columns are always sorted alphabetically
SELECT name, email, age, ->buys->item as bought from user:1 fetch bought /// [ { "time": "101.532µs", "status": "OK", "result": [ { "age": null, "bought": [ { "id": "item:1", "name": "some item", "price": "999.99" } ], "email": null, "name": "SurrealDB" } ] } ]
This mostly involves these tasks:
import _ "github.com/go-sql-driver/mysql"
)