当前位置:网站首页>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
边栏推荐
- PCL点云处理之基于PCA的几何形状特征计算(五十二)
- I JS deep copy and shallow copy
- Automatically fill in body temperature and win10 task plan
- R language uses timeroc package to calculate the multi time AUC value of survival data under competitive risk, uses Cox model and adds covariates, and R language uses the plotauccurve function of time
- LeetCode 232、用栈实现队列
- SIGIR'22 "Microsoft" CTR estimation: using context information to promote feature representation learning
- 上海回应“面粉官网是非法网站”:疏于运维被“黑”,警方已立案
- Is the wechat CICC wealth high-end zone safe? How to open an account for securities
- Actual measurement of automatic ticket grabbing script of barley network based on selenium (the first part of the new year)
- [graph theory brush question-5] Li Kou 1971 Find out if there is a path in the graph
猜你喜欢
SIGIR'22 "Microsoft" CTR estimation: using context information to promote feature representation learning
SQL Server Connectors By Thread Pool | DTSQLServerTP plugin instructions
Installation and use of NVM
Livego + ffmpeg + RTMP + flvjs to realize live video
Click an EL checkbox to select all questions
Azkaban recompile, solve: could not connect to SMTP host: SMTP 163.com, port: 465 [January 10, 2022]
On BIM data redundancy theory
Linux64Bit下安装MySQL5.6-不能修改root密码
Commit and rollback in DCL of 16 MySQL
Building the tide, building the foundation and winning the future -- the successful holding of zdns Partner Conference
随机推荐
Azkaban recompile, solve: could not connect to SMTP host: SMTP 163.com, port: 465 [January 10, 2022]
SQL Server Connectors By Thread Pool | DTSQLServerTP plugin instructions
Click an EL checkbox to select all questions
Confusion about thread blocking after calling the read () method of wrapper flow
一. js的深拷贝和浅拷贝
Research on open source OCR engine
How do BIM swindlers cheat? (turn)
PCL点云处理之直线与平面的交点计算(五十三)
Mathematical modeling column | Part 5: MATLAB optimization model solving method (Part I): Standard Model
ABAQUS script email auto notification
Sqoop imports tinyint type fields to boolean type
DTMF dual tone multi frequency signal simulation demonstration system
PCL点云处理之计算两平面交线(五十一)
Don't bother tensorflow learning notes (10-12) -- Constructing a simple neural network and its visualization
Notes of Tang Shu's grammar class in postgraduate entrance examination English
LeetCode 994、腐烂的橘子
Matlab analytic hierarchy process to quickly calculate the weight
selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ executable needs to be in PAT
Redis cache penetration, cache breakdown, cache avalanche
[PTA] get rid of singles