New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can you insert a struct without using a command? #29
Comments
Hi, @josebalius! This is related to #27. I intend to implement a way to convert a structs to Documents shortly, and this will allow to write something like this: var a MyStruct
doc := orient.ToDocument(a)
db.CreateRecord(doc) Is that a behavior you asking about? The long way in example above is intentional, as it allows to set a RID on Document (this changes default cluster of a record). After some time I will also implement a way to register Go structs as a class for OrientDB, using fields to set type constraint, allowing to just insert a struct to certain cluster. This will be more ORM-like :) |
@dennwc yep exactly what I mean, that would be awesome! |
Implemented. First step to #6. var a MyStruct
doc := orient.NewDocument("Structs") // cluster or class name
_ = doc.From(a) // can return conversion error
err := db.CreateRecord(doc) // doc will be updated with new record RID and version
a.Data = "some changes"
doc.From(a) // fill doc with changes
err = db.UpdateRecord(doc) // version will be updated @josebalius feel free to reopen this issue if you have any related questions or proposals |
@dennwc So it looks like it can't convert structs that have consts with iota on them (go enums) :/ What do you recommend I do? Need an example or you know what I mean? |
@josebalius I suspect the problem is not the struct. You was using a custom type |
@ympons yes, its the custom type but is there anyway to support this? otherwise the enum pattern recommended by Go won't ever be compatible with this. I guess i can just use "int" as my type but that makes me sad :( |
Maybe we could use a struct tag to specify how to convert the custom type? It's just an int at the end of the day. |
This is not a big problem. It only needs a small tweak in a type converter. I will check it tomorrow. Also, please open a new issue for that, or reopen issue #37. |
@dennwc Can you please provide an example on how to use the |
@dennwc I keep getting
|
So I added |
Right, Document.RID is the only way for now to determine which record to update. Related to #32 . |
I tried playing around with the Document type but could not figure out a way to simply insert a struct without writing an insert statement.
I realize this is more "ORM" but I was wondering if it was currently possible?
Thanks!
Jose
The text was updated successfully, but these errors were encountered: