Comments (10)
from gen.
@November-12 是不是改了这个配置,https://gorm.io/docs/gorm_config.html#NamingStrategy
SingularTable, // use singular table name, table for
Userwould be
userwith this option enabled
from gen.
@November-12 是不是改了这个配置,https://gorm.io/docs/gorm_config.html#NamingStrategy
SingularTable, // use singular table name, table for
Userwould be
userwith this option enabled
您好~确实没有改动过任何配置,仅仅升级了版本。
from gen.
@November-12 那辛苦配置下 上面那个配置,看看能解决问题不
from gen.
@November-12 那辛苦配置下 上面那个配置,看看能解决问题不
尝试了之后无法解决,这个SingularTable他影响的是“表名”的单复数,我遇到的问题是“字段名”的单复数被修改了,这个好像没有没发现可以配置的地方。
from gen.
@November-12 如果是默认的话,字段名也会用这个策略,SchemaName
方便发下你的配置吗?gorm和gen的配置
from gen.
@November-12 如果是默认的话,字段名也会用这个策略,
SchemaName
方便发下你的配置吗?gorm和gen的配置
gen的配置:
`package main
import (
initialize "project/initialize"
"gorm.io/gen"
)
func main() {
g := gen.NewGenerator(gen.Config{
OutPath: "../../query",
Mode: gen.WithoutContext | gen.WithDefaultQuery | gen.WithQueryInterface, // generate mode
FieldNullable: true,
})
initialize.ViperInit("../../configs/conf.yml")
initialize.LogInIt()
gormdb := initialize.PgInit()
if gormdb == nil {
panic("gormdb is nil")
}
g.UseDB(gormdb)
g.ApplyBasic(
g.GenerateAllTable()...,
)
g.Execute()
}
`
gorm的配置:
`func PgConnect(config *DbConfig) (*gorm.DB, error) {
dataSource := fmt.Sprintf("host=%s port=%d dbname=%s user=%s password=%s sslmode=disable TimeZone=%s",
config.Host, config.Port, config.DbName, config.Username, config.Password, config.TimeZone)
newLogger := logger.New(Writer{}, logger.Config{
SlowThreshold: time.Duration(config.SlowThreshold) * time.Millisecond,
LogLevel: logger.LogLevel(config.LogLevel),
IgnoreRecordNotFoundError: true,
Colorful: true,
})
var err error
db, err := gorm.Open(postgres.Open(dataSource), &gorm.Config{Logger: newLogger})
if err != nil {
return nil, fmt.Errorf("连接数据库失败: %v", err)
}
sqlDB, err := db.DB()
if err != nil {
return nil, fmt.Errorf("获取原生数据库连接失败: %v", err)
}
sqlDB.SetMaxIdleConns(config.IdleConns)
sqlDB.SetMaxOpenConns(config.OpenConns)
sqlDB.SetConnMaxLifetime(time.Hour)
log.Println("连接数据库完成...")
// 检查版本
err = CheckVersion(db)
if err != nil {
fmt.Println(err)
}
return db, nil
}`
from gen.
@November-12 如果是默认的话,字段名也会用这个策略,
SchemaName
方便发下你的配置吗?gorm和gen的配置
我这边测试了几遍‘SingularTable’这个参数,确实是表名会应用这个策略,字段名则不会,都会被转换为单数。
from gen.
@November-12 gorm和gen的版本变化也发下吧
from gen.
@November-12 配置没看出问题,但是逻辑我也确认了 第一个版本到现在都是没变化的
if ns, ok := db.NamingStrategy.(schema.NamingStrategy); ok { ns.SingularTable = true m.Name = ns.SchemaName(ns.TablePrefix + m.Name) }
from gen.
Related Issues (20)
- 能不能仅生成model 不生成query啊 HOT 1
- 能否数据库不加外键也能使用FieldRelateConfig
- gen.Table 获取了一个空的 select * from
- 请问使用表达式更新时是否可以增加判断条件呢? HOT 2
- 使用gen生成Sqlite引擎的model时字段丢失了index tag
- GEN Can't generate correct time-related SQL
- 非主键但是是uniqueIndex的自增没有生成
- 希望gentool工具也支持下表前缀和列前缀
- Order By 无法执行自定义排序
- GEN Generate unique aware unit tests.
- The return value Count of the FindByPage function is always 0.
- 从sqlserver数据库将numeric字段逆向生成uint8
- gentools install broke yesterday - go install gorm.io/gen/tools/gentool@latest fails HOT 11
- 在使用 GenerateModel 时,总是将字段中的 ssh 转换为 SSH,想要转换为 Ssh HOT 1
- Gentool generates invalid tags on Postgres SERIAL PRIMARY KEY column
- Query generation with existing database table named "fields" HOT 1
- 使用动态sql生成的方法,Preload加载关联的关系失败
- embed custom model for generated model
- Is there a way to add `db` tag HOT 1
- How to keep model name 's' prefix? 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 gen.