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)
- Support for SurrealDB
- DB.Table(myTable).AutoMigrate(&myStruct) does not implement the gorm struct tags like uniqueIndex:idx_name on that struct HOT 1
- 中文文档里的问题 HOT 1
- 多次调用db.AutoMigrate()会对之前的model重复执行 HOT 1
- Context management in GORM
- Remove double quotes from generated SQL to support lowercase table and column names HOT 1
- Postgres删除约束时,未处理根据schema进行的方式 HOT 4
- Grouped conditions in scopes results in duplicative where conds
- BUG:`PrepareStmt:true` 在 SQL 执行时错误 `PreparedSQL` 会内存泄露 HOT 6
- Connect Postgresql failed in AWS Lambda HOT 1
- Connect Postgresql failed in AWS Lambda HOT 2
- Gorm lack of performance!?
- Many2Many associations cause AutoMigrate to create joining tables with the wrong data types; then foreign key constraints fail. HOT 2
- Lazy Connections with Read/Write splitting
- Initialization with no default dialector
- gorm 1.25.1 版本,当表结构发生变更时,调用AutoMigrate方法时出现报错:got 1 parameters but the statement requires 0 HOT 1
- With gorm and the sqlite driver that comes with gorm, when storing a number of the string type, if the number is very long, then the number is stored in the database as a scientific notation
- 针对下列复杂SQL查询,GORM怎么处理? HOT 3
- mysql JSON_SET cannot be used in many ways HOT 2
- “删除关联”无法正常工作 HOT 1
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.