当前位置:网站首页>Go zero framework database avoidance Guide
Go zero framework database avoidance Guide
2022-04-23 20:24:00 【Deng_ Xian_ Sheng】
Let's start with a problem that doesn't seem to be a problem ,zero The package that should be imported may be missing from the source code generated by the framework or given in the document
If you use goland Will automatically import ; But if it is vscode Or other editors need to pay attention to this problem
————————————————————————————————————————-——
Let's go on zero Framework database related
zero It's generating insert、update These two fields are excluded by default when coding
create_time
update_time
however , barring delete_time
; Read through the generated code and you will find ;insert In the code delete_time
As a necessary parameter, it is embedded in the code ; If this field is not filled in the structure of the parameter transfer ; May get Incorrect datetime value: '0000-00-00' for column 'delete_time' at row1
therefore , You need to exclude this field , Or write it yourself insert Code
# Exclude this field
userRowsExpectAutoSet = strings.Join(stringx.Remove(userFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
Another question
For special fields , Note that null problem
#delete_time The field should be allowed to be null, And the default for null
`delete_time` timestamp(3) NULL DEFAULT NULL,
`create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
If sql Field constraints 、 Incorrect type ; This may happen to the generated code
DeleteTime time.Time `db:"deleted_at"`
CreateTime time.Time `db:"created_time"`
UpdateTime time.Time `db:"updated_time"`
It should have been
DeleteTime sql.NullTime `db:"deleted_at"`
CreateTime time.Time `db:"created_time"`
UpdateTime time.Time `db:"updated_time"`
If you need to modify the fields of a table later , Generated CURD In addition to the structure of the table ;CURD The function also needs to be modified ; Otherwise, there will be some problems .( because CURD The function of is highly coupled to the structure of the table )
In general zero The point is still rpc, send rpc Better to use ; It's simpler .
For the encapsulation of database, the general situation is , Don't over rely .
版权声明
本文为[Deng_ Xian_ Sheng]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204232018198102.html
边栏推荐
- Markdown < a > tag new page open link
- How to protect ECs from hacker attacks?
- R language survival package coxph function to build Cox regression model, ggrisk package ggrisk function and two_ Scatter function visualizes the risk score map of Cox regression, interprets the risk
- Analysis of the relationship between generalized Bim and CAD under the current background
- 如何做产品创新?——产品创新方法论探索一
- SQL Server Connectors By Thread Pool | DTSQLServerTP plugin instructions
- PostgreSQL basic functions
- Is the wechat CICC wealth high-end zone safe? How to open an account for securities
- Commit and rollback in DCL of 16 MySQL
- 微信中金财富高端专区安全吗,证券如何开户呢
猜你喜欢
. Ren -- the intimate artifact in the field of vertical Recruitment!
【PTA】L1-002 打印沙漏
LeetCode 542、01 矩阵
Handwritten Google's first generation distributed computing framework MapReduce
Matlab analytic hierarchy process to quickly calculate the weight
How can matlab obtain the truncated image in trainingimagelabeler
Notes of Tang Shu's grammar class in postgraduate entrance examination English
Wave field Dao new species end up, how does usdd break the situation and stabilize the currency market?
波场DAO新物种下场,USDD如何破局稳定币市场?
On BIM data redundancy theory
随机推荐
PostgreSQL basic functions
LeetCode 994、腐烂的橘子
Scrapy教程 - (2)寫一個簡單爬蟲
Historical track data reading of Holux m1200-e Bluetooth GPS track recorder
PCA based geometric feature calculation of PCL point cloud processing (52)
JDBC database addition, deletion, query and modification tool class
How to protect ECs from hacker attacks?
PCL点云处理之基于PCA的几何形状特征计算(五十二)
[problem solving] 'ASCII' codec can't encode characters in position XX XX: ordinal not in range (128)
SQL Server Connectors By Thread Pool | DTSQLServerTP plugin instructions
Notes of Tang Shu's grammar class in postgraduate entrance examination English
ArcGIS JS version military landmark drawing (dovetail arrow, pincer arrow, assembly area) fan and other custom graphics
SQL gets the latest record of the data table
star
Actual measurement of automatic ticket grabbing script of barley network based on selenium (the first part of the new year)
Zdns was invited to attend the annual conference of Tencent cloud basic resources and share the 2020 domain name industry development report
How does onlyoffice solve no route to host
Scripy tutorial - (2) write a simple crawler
[latex] 5 how to quickly write out the latex formula corresponding to the formula
Monte Carlo py solves the area problem! (save pupils Series)