GORM 配置
3 分钟阅读
GORM provides Config can be used during initialization
GORM提供了Config可以在初始化时使用。
|
|
SkipDefaultTransaction
GORM perform write (create/update/delete) operations run inside a transaction to ensure data consistency, you can disable it during initialization if it is not required
GORM在执行写(创建/更新/删除)操作时,会运行在一个事务中以确保数据一致性,如果在初始化时不需要,可以禁用它
|
|
NamingStrategy
GORM allows users to change the naming conventions by overriding the default NamingStrategy
which need to implements interface Namer
GORM允许用户通过覆盖默认的NamingStrategy
来改变命名约定,需要实现接口Namer
|
|
The default NamingStrategy
also provides few options, like:
默认的NamingStrategy
还提供了一些选项,例如:
|
|
Logger
Allow to change GORM’s default logger by overriding this option, refer Logger for more details
允许通过覆盖此选项来更改GORM的默认日志记录器,有关更多详细信息,请参阅Logger
NowFunc
Change the function to be used when creating a new timestamp
更改创建新时间戳时要使用的函数
|
|
DryRun
Generate SQL
without executing, can be used to prepare or test generated SQL, refer Session for details
生成SQL
而不执行,可用于准备或测试生成的SQL,有关详细信息,请参阅Session
|
|
PrepareStmt
PreparedStmt
creates a prepared statement when executing any SQL and caches them to speed up future calls, refer Session for details
PreparedStmt
在执行任何SQL时创建一个预处理语句并将其缓存以加速未来的调用,有关详细信息,请参阅Session
|
|
DisableNestedTransaction
When using Transaction
method inside a db transaction, GORM will use SavePoint(savedPointName)
, RollbackTo(savedPointName)
to give you the nested transaction support, you could disable it by using the DisableNestedTransaction
option, refer Session for details
在使用db事务内的Transaction
方法时,GORM将使用SavePoint(savedPointName)
,RollbackTo(savedPointName)
提供嵌套事务支持,您可以通过使用DisableNestedTransaction
选项禁用它,有关详细信息,请参阅Session
AllowGlobalUpdate
Enable global update/delete, refer Session for details
启用全局更新/删除,有关详细信息,请参阅Session
DisableAutomaticPing
GORM automatically ping database after initialized to check database availability, disable it by setting it to true
GORM在初始化后自动ping数据库以检查数据库可用性,通过将其设置为true
禁用它
|
|
DisableForeignKeyConstraintWhenMigrating
GORM creates database foreign key constraints automatically when AutoMigrate
or CreateTable
, disable this by setting it to true
, refer Migration for details
GORM在AutoMigrate
或CreateTable
时自动创建数据库外键约束,禁用此选项,将其设置为true
,有关详细信息,请参阅Migration
|
|