[ANN] A Typed ORM Library

199 views
Skip to first unread message

Eyal Posener

unread,
Dec 22, 2017, 2:32:59 PM12/22/17
to golang-nuts

Hi


In the last month I spent my free time on creating a typed ORM library for Go.

The motivation was that the currently most popular ORM library for Go: GORM, lacks type safety, has poor performance and, to my opinion, has unclear API.

Don't get me wrong, GORM is great, but I think that the go community can have something more Go-ish.


So what was I thinking about?... About this: https://github.com/posener/orm


What is it? A command line that generates typed ORM code for a specific struct.

The generated code does not use any interface{}, everything is typed! From function arguments for insert operations, to arguments that are passed to a where statement, and to returned values from a query operation. No more guessing, no more run time failures.


The current implementations supports:


* Two database drivers: mysql (tested with mysql 5.6), and sqlite3

* Relatively simple API.

* Create table, simple migrations (add column, add foreign key column)

* Tables relations: one to one, one to many.

* Query: select columns, filter with where, group by, order by, joins (by primary key(s)), rows count.

* Insert:  a row. returned value is typed and has the primary key(s) filled.

* Delete: according to a where statement.

* Update: only to a specific value.


Simple benchmarks are available, showing performance similar to raw SQL queries performance.


This is a big task, and to my opinion, it is an important one.

I would love to get help! and this project is on it's first stages, everything is open!


* Add support for other databases.

* Add functionalities.

* Suggest ideas.

* Suggest better design.

* Suggest better API.

* Wider auto migration options.

* Support migration scripts generation.

* Improve documentation, add examples, improve wiki.

* Add tests.


Please visit https://github.com/posener/orm, star, and contribute.

And please, your opinion about it is appreciated!


Cheers,

Eyal


Tamás Gulácsi

unread,
Dec 22, 2017, 3:49:37 PM12/22/17
to golang-nuts
Have you seen knq/xo ?

Eyal Posener

unread,
Dec 22, 2017, 5:53:46 PM12/22/17
to golang-nuts
Hi Tamas,
Thanks for the link, haven't seen that tool.
Actually, as I understand, it is exactly the opposite, xo generates go code from SQL database.
A comparable tool I found is https://github.com/relops/sqlc.

On Friday, December 22, 2017 at 10:49:37 PM UTC+2, Tamás Gulácsi wrote:
Have you seen knq/xo ?

Alexey Palazhchenko

unread,
Dec 23, 2017, 2:21:09 PM12/23/17
to golang-nuts
Hi,


–-–
Alexey «AlekSi» Palazhchenko

Eyal Posener

unread,
Dec 23, 2017, 2:53:52 PM12/23/17
to golang-nuts
Nice stuff Alexey! thanks for this link, haven't seen it so far.
Seems like we both got frustrated from the same issues with existing solutions :-)

We took pretty different approaches to solve the typed-ORM problem though.
The reform library has a larger run-time content, and keeps the generated code minimal, which is a very nice idea!
However, as it seems to me, there are still a lot of interface{}s, and strings to pass to the library functions, which I try to avoid. The current proposed orm implementation leaves zero guessing - the user does not need to know column names, SQL queries, expressions or types. All the functions are fully typed, which leaves no room for run-time bugs. I intend to keep it like that as much as possible.
I would love to hear your opinion about it, and if you could enlighten me with obstacles I will find in future development of this library, since it seem like you have some experience in this field.

Cheers!
Reply all
Reply to author
Forward
0 new messages