ORM & Database #110
Replies: 9 comments 19 replies
-
A list of ORMs: |
Beta Was this translation helpful? Give feedback.
-
I'm used to GORM but I feel a little lack of a well written documentation, looks like I'm reading the code comments instead of the official doc. Seizing the theme, I'm assigned to the Validation Depth and an ORM would be required for some validation, for example the "unique" keys, would need to verify the table and search for a value(you know). So if there's no rush to implement an ORM would be nice to wait for a Generics so we could think and project calmly an Eloquent-ish package. |
Beta Was this translation helpful? Give feedback.
-
I like the idea of waiting. |
Beta Was this translation helpful? Give feedback.
-
I use gorm in some of my projects as well and building the query feels really a bit of "laravel-like". Here an example out of one of my projects: dbc := db.Connection()
courseDataReversed := []db.HistoricCourse{}
dbc.Select("avg(btc) as btc, avg(eth) as eth, avg(ltc) as ltc, avg(bch) as bch, min(id) as id, created_at").
Table("historic_courses").
Where("created_at < ?", t.currentTime).
Where("created_at > ?", t.currentTime.Add((-1)*24*8*time.Hour)).
Group("created_at_quarter_hour").
Order("created_at DESC").
Limit(7*24*4 + 5).
Find(&courseDataReversed) The syntax is not that beautiful than it's in laravel but I feel that it's kinda easy to use. I have to admit that @rafaelbreno is right according the documentation. If you have special things to solve (complex subqueries, multiple joins, etc) there are very few examples to work with. |
Beta Was this translation helpful? Give feedback.
-
Recommend REL
|
Beta Was this translation helpful? Give feedback.
-
Hello everyone, I really loved the framework, but I don't where it will be better to put database functions, I mean I used to open one database connection in my main.go file then I use it any where, just by passing credential. So, the question is, where it will be better to put my db functions, what I used to do is: // In main.go
db, err := sql.Open("mysql", dbUsername + ":" + dbPassword + "@/" + dbName)
if err != nil {
panic(err.Error())
}
defer db.Close()
// then in my other functions/routes, I pass the db, then credentials
createData(db, ...)
// here is the function
func createData(db *sql.DB, ...) {/* ... */} Thx for attention. |
Beta Was this translation helpful? Give feedback.
-
Also have https://entgo.io |
Beta Was this translation helpful? Give feedback.
-
Generics are available now. Are there any plans? |
Beta Was this translation helpful? Give feedback.
-
Our team has implemented https://github.com/volatiletech/sqlboiler successfully in some projects before. It's a great way to setup models from your migrations and then use those models those setup database seeds. It takes away the heavy lifting of creating db boilerplate throughout projects. |
Beta Was this translation helpful? Give feedback.
-
I've thought about that for a long time. But I think we should wait for Generics in Go. I can make all subjects in such a way that gives the same feeling as Laravel, only an ORM needs generics in my opinion.
We could create or accept a query builder. How do we think about that?
Beta Was this translation helpful? Give feedback.
All reactions