Comments (1)
For me, I think this is not the best way to do it, I am doing it like this:
// xxx/db.go
var DB gorm.DB
func init() {
DB = gorm.Open("mysql", "xxxxxx")
}
// xxx/user.go
import . "xxx/db.go"
func Users() (users []User) {
DB.Table("user").Find(users)
}
Then if you want to change to any other ORM, you just need to change the db package if the syntax is same.
from gorm.
Related Issues (20)
- Default value for text type is not showing in generated structs HOT 1
- Support duckdb HOT 1
- How to get transaction ID by gorm? HOT 1
- SQL printed to terminal is error
- GORM Save model with Associations but incorrect work HOT 4
- GORM save to map seems to require a model even though the table name is being specified
- Can Gorm elegantly update null value columns? HOT 1
- GORM save to map causes crash when model type includes primary key field (solution shown) HOT 3
- Why Pluck column type is time.Time value no results, but column type is string value have results. HOT 2
- 批量创建时,当传递的dst的元素是Interface时报错 HOT 2
- Why does db.RowsAffected return 0 after the data is updated? HOT 1
- Why does db.RowsAffected return 0 after the data is updated? HOT 7
- 多次调用Model方法 只有第一次调用更新了表名 后续调用Model方法无效 HOT 1
- GORM无法操作数据库的视图,无法想映射Molde一样映射一个Struct类型来操作数据库创建的视图结构,并进行CRUD!拜托!这么重要的功能都没有! HOT 1
- Inner join with condition
- Can't get data from columns that names contain numbers HOT 4
- betch save model, on conflict by uniqueIndex, return id err HOT 1
- betch save model, on conflict by uniqueIndex, return id err
- one to many with subquery join does not scan to parent struct HOT 1
- prepareStmt is not support for ping function HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gorm.