Comments (7)
相对而言,gorp的应该还好一点,因为可以注册一次,以后永久使用,
beedb 是不是每次都需要设定table name?
其实现在gorm也支持设定table,不过是有点类似beedb,每次都要设定,可以看看这里
https://github.com/jinzhu/gorm#specify-table-name
我想一下永久性方案吧,做起来应该挺简单的,只是我这里没有遗留项目要转gorm,所以没有太关注这个功能。。。 ;)
from gorm.
可以考虑在struct中定义meta字段, 专门用于保存表相关数据, 内部处理时忽略该字段, 例如
type User struct{
table_name int8 "my_users"
}
定义为int8是为了节省空间. 如果为了将来扩展, 也可以更深入一些
type User struct{
_meta int8 "gorm:table_name=my_users;otherdata=xxxxx"
}
缺点显而易见, 每个对象都要浪费一个字节的空间, 当对象数量非常庞大时, 也可能是个问题. 不过在我自己的应用场景中倒不算什么.
from gorm.
我不太喜欢tag的方式,因为感觉他污染了struct... ;(
并且每次都处理下tag, 不知道会影响多少速度。。。
from gorm.
是的, tag非结构化数据会让人感觉代码既脆弱又不够光滑:)
from gorm.
嗯,所以我尽量不使用tag。。。 等感觉到找不到其它办法描述的时候再用它
from gorm.
我增加了几个方式,可以通过 db.SingularTable(true)
来关闭复数表名,
struct 的 TableName() 方法来设定表名,参考
https://github.com/jinzhu/gorm#specify-table-name-for-struct
这样子,你可以通过这个方法来设定任何表名了,例如可以根据用户的角色不同设定不同的表名。
from gorm.
nice, clean and readable
from gorm.
Related Issues (20)
- Wrong table creation order causes migration failure (but not in SQLite)
- More efficient preloading
- Add derived column along with default fields
- 查找不到数据的时候,err与gorm.ErrRecordNotFound比较的结果是false HOT 5
- Update multiple rows with different values in one query in postgres
- Save struct with same relation in associated table HOT 1
- Scan row into multiple structs
- feature: add Chinese README.md
- N+1 Queries with Joins("Company").Preload("Company.Addresses") on Addresses
- What happens when IN clause is too big?
- Document how to use Gorm with Cloud SQL Go Connector HOT 2
- Model() ignores primary key in passed argument
- main.go:5:2: gorm.io/[email protected]: Get "https://proxy.golang.org/gorm.io/gorm/@v/v1.25.9.zip": dial tcp 172.217.163.49:443: i/o timeout HOT 1
- 使用gorm生成的sql能查询到数据,但是返回的结构体里面没有数据 HOT 1
- gorm join时候没有对关联表的软删除进行过滤 HOT 1
- 使用join关联查询数据时候发现关联表没有自动过滤掉软删除的数据
- Is there any option to return null instead object with zero id in belong relations ?
- Serialization error on update HOT 3
- Where Condition Build Issue HOT 2
- json query with boolean argument fails
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.