Working on a SurrealDB driver #7363
Replies: 1 comment
-
I have made a few advances here - and perhaps a little "critique": Every Further, the statements (or clauses, I guess?) are split quite deeply. Overwriting I have yet to figure out If I find the time, I would love to document the process of implementing a driver - where would I send the PR for that, in fact? to the Thanks! |
Beta Was this translation helpful? Give feedback.
-
Hello there!
Yesterday I crunched out a
database/sql[/driver]
interface for Go, for surrealDB. It works and I am currently expanding on the test coverage to make sure that everything works as intended. But, the primary motivation for writing this in the first place, was so that I could use GORM. If there is one thing lacking for SurrealDB, then it's tooling. Cool to have these AI features and advanced table opterations and whatnot - but, without good tooling, it's just... fancy. x)so, I decided to forego their official Go module (it uses CBOR and is half-broken) and write my own. And now, I am all over the GORM docs, trying to find out what I need to implement in order to write my driver - well,
Dialector
.A few things I noticed while looking at the MySQL one that I must implement differently, but do not know how to, yet:
{"id":"abc", "method":"query", ["SELECT * from $tbl", { "tbl": "mytable" }]}
will already do the variable substition. My driver also implements that by using thelet
method for prepared statements, or inlines them as shown in this message. But, how do I do that for GORM? The interface specifiesBindVarTo(...)
. How exactly am I supposed to work with this? Store the variables in the current connection object and then pick it up later at query time?CREATE person VALUES <jsonObject>
. The only notable "type" would be when referencing other table entries (record IDs) - those are simply not quoted. So I need to deal with that in a special way. Those record IDs also make up the primary key by default, by the way. Each record has an ID field like"ID": mytable:someidentifier
(the string is quoted in the JSON reply, but technically it shouldn't be.) Where, or how, do I handle them? Looking at the custom clauses - like the LIMIT one given in the docs - this only seems to apply to certain expressions. However, features likeREINDEX
,UPSERT
,LIVE
andKILL
- let alone all the event features - are custom queries. They are rather optional, but for completeness-sake, I would love to implement them properly. Where, and how, do I do that?I am still figuring most of the interfaces out - but I am under a wee bit of time pressure to finish this project sooner rather than later...so I have to go the hybrid approach of asking here, reading the docs, and building into the void an dhope things stick x) Apologies for the lil' bit of chaos.
Thank you very much and kind regards!
Beta Was this translation helpful? Give feedback.
All reactions