5 ms·
Python : Django === Go : ?? If I want a nice ORM and built in migrations, what framework should I be using 10 years later?
by misiti3780 7y ago
Python : Django === Go : ??
If I want a nice ORM and built in migrations, what framework should I be using 10 years later?
- vthallam 7y agoYou don't have a single famous one because Go developers tend to hate frameworks and ORM's. If you are interested, I have wrote about some alternatives before here - https://hackernoon.com/the-myth-about-golang-frameworks-and-external-libraries-93cb4b7da50f https://hackernoon.com/the-myth-about-golang-frameworks-and-...
- eternalban 7y agoThe actual reason is that the language lacks the meta-programming facilities required for creating effective ORMs and certain frameworks. (Whether this is a good thing or a bad thing is a subjective matter.)
- sedeki 7y agoExactly. There's not much choice. The best approximations are considered hacks.
- tombert 7y agoWait, is that true? I thought that the Java packages like Hibernate were just using method attributes and reflection...doesn't Go have the ability to add attributes to structs and a working reflection library?
- zaphar 7y agoThey use generics pretty heavily too so it's not only reflection. Generics allow them to do a typesafe interface for the developer to use as well as making less work for the reflection code to do.
- eternalban 7y agoAnd annotations and classloaders. Haven't looked at Hibernate in years ("10 years" to be exact /g) but it is possible that it also requires Java and JVM's instrumentation facilities. So certain kind of software magic can't be done with Go. Options in Go for effective ORM require source level processing.
- kissgyorgy 7y agoYes, Go has a reflection package, but it's terrible. Nowhere near has the power compared to Python's metaprogramming capabilities.
- excursionist 7y agoGo has reflection, but it doesn't have annotations or generics. Annotations are key for libraries such as hibernate.
- noisem4ker 7y agoAren't `tags` akin to annotations?
- excursionist 7y agoNo, Go tags are like metadata which can be accessed through reflection at runtime. Java annotations allow you to actually generate code during the build phase.
- EdwardDiego 7y agoI've encountered a bunch of code generation in client-go - I'm not very good at Go, so not sure what the term for the code generation directives in comments is, if there is one.
- badrequest 7y agosqlx (1) is probably the closest thing to a tradition ORM that operates this way ^1: https://github.com/jmoiron/sqlx https://github.com/jmoiron/sqlx
- skybrian 7y agoI'm not sure that's really a showstopper if you really want to do it? Code generation is powerful and it can be done outside the language.
- Rapzid 7y agoI don't believe that to be true. There are almost too many ORMs for Golang. Golang has had an issue with fractured ecosystems from the start. Part of this had to do with lack of a package manager. Part of it had to do with companies and developers wanting to move fast and not get bogged down trying to get changes through other peoples process and into their repo. Or perhaps development stalled out as the ORM met the requirements of the developers/project, or for other reasons. If you evaluate carefully each of the available ORMs it becomes apparent that a lot of them have different short comings and trade-offs, and were created around some theme or feature set missing from the others.
- conroy 7y agoI wasn't happy with the current database access packages (https://github.com/jmoiron/sqlx https://github.com/jmoiron/sqlx, https://gorm.io https://gorm.io), so I wrote my own for PostgreSQL. It takes existing queries and generates type-safe Go methods (https://github.com/kyleconroy/sqlc https://github.com/kyleconroy/sqlc). I enjoy using it and thought others might too. As for migrations, I've had success with https://github.com/pressly/goose https://github.com/pressly/goose. It's lightweight and is also just SQL.
- erik_seaberg 7y agoNice, much like people would use Pro*C to generate C to talk to Oracle. I think converting a DSL to boilerplate (which should rarely be read and never edited) is key to living with a language that isn't good at reusable abstractions.
- badrequest 7y agoI've been using Darwin(1) for migrations, personally. ^1: https://github.com/GuiaBolso/darwin https://github.com/GuiaBolso/darwin
- cygned 7y agoI am in the “we don’t need an ORM camp” but what I need instead is a flexible query builder. Like knex for JavaScript. I have yet to find that one.
- deleted 7y ago[deleted]
- reificator 7y agoDoes Squirrel cover your needs? https://github.com/Masterminds/squirrel https://github.com/Masterminds/squirrel
- cygned 7y agoI was using Squirrel and goqu extensively. Both are nice, not as easy and flexible as knex. That is basically a language constraint, JavaScript’s dynamic typing allows for all kinds of shortcuts Go cannot offer.
- malvosenior 7y agoI think in the past 10 years there's been a real move away from ORM so I wouldn't expect it in the Go ecosystem. SQL is the best way to interface with a RDBS.
- mattigames 7y agoYeah, untyped syntax inside your statically typed language, what could be better.
- reificator 7y agoWhat's preventing you from using a query builder?
- mattigames 7y agoThen the accurate thing to say is "a SQL query builder is the best way to interface with a RDBS"
- malvosenior 7y agoAs a query DSL I don't find a problem with that. It's like saying that query strings in urls are untyped so don't match well. In reality the gap between untyped->typed is super narrow. You almost always immediately scan the results of your query into typed struct fields.
- Rapzid 7y agoI haven't seen that at all. Every popular open source project that comes to mind uses an ORM in some form or fashion. I'm sure they exist but I can't think of a single one that is just doing raw SQL or Query building, across any programming language for that matter. Heck, I think GOGS/GITEA are the reason xorm even exists. There are a number of ORMs for golang, they just all have their pros and cons.
- mikelbring 7y agoBuffalo (https://gobuffalo.io/ https://gobuffalo.io/) seems to be getting popular but can't speak from personal experience
- hellcow 7y agoNot a framework, but I wrote a migration tool compatible with several SQL databases: https://github.com/egtann/migrate https://github.com/egtann/migrate. It ensures consistency can always be reached (the most important feature for a migration tool IMO, yet most tools do not guarantee this) and uses standard SQL syntax in migration files.
- cyberpunk 7y agoI highly recommend you check out elixir + phoenix