当前位置:网站首页>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
边栏推荐
- Redis installation (centos7 command line installation)
- The R language uses the timeroc package to calculate the multi time AUC value of survival data without competitive risk, and uses the confint function to calculate the confidence interval value of mul
- 16MySQL之DCL 中 COMMIT和ROllBACK
- Mathematical modeling column | Part 5: MATLAB optimization model solving method (Part I): Standard Model
- Linux64Bit下安装MySQL5.6-不能修改root密码
- Cadence OrCAD capture batch change component packaging function introduction graphic tutorial and video demonstration
- 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
- PCL点云处理之基于PCA的几何形状特征计算(五十二)
- Cadence Orcad Capture 批量更改元件封装功能介绍图文教程及视频演示
- [PTA] l2-011 play with binary tree
猜你喜欢

RT-1052学习笔记 - GPIO架构分析

SQL Server connectors by thread pool 𞓜 instructions for dtsqlservertp plug-in

Operation of numpy array

DTMF dual tone multi frequency signal simulation demonstration system

SQL Server Connectors By Thread Pool | DTSQLServerTP 插件使用说明

An error is reported when sqoop imports data from Mysql to HDFS: sqlexception in nextkeyvalue

2022DASCTF Apr X FATE 防疫挑战赛 CRYPTO easy_real

Rt-1052 learning notes - GPIO architecture analysis

WordPress plug-in: WP CHINA Yes solution to slow domestic access to the official website

The ODB model calculates the data and outputs it to excel
随机推荐
RT-1052学习笔记 - GPIO架构分析
DNS cloud school | quickly locate DNS resolution exceptions and keep these four DNS status codes in mind
SQL gets the latest record of the data table
【PTA】L1-006 连续因子
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
Scrapy教程 - (2)寫一個簡單爬蟲
2022dasctf APR x fat epidemic prevention challenge crypto easy_ real
LeetCode 994、腐烂的橘子
LeetCode 1346、检查整数及其两倍数是否存在
XXXI` Prototype ` displays prototype properties and`__ proto__` Implicit prototype properties
Livego + ffmpeg + RTMP + flvjs to realize live video
【PTA】整除光棍
Mysql database and table building: the difference between utf8 and utf8mb4
star
Paper writing 19: the difference between conference papers and journal papers
6-5 字符串 - 2. 字符串复制(赋值) (10 分)C语言标准函数库中包括 strcpy 函数,用于字符串复制(赋值)。作为练习,我们自己编写一个功能与之相同的函数。
Analysis of the relationship between generalized Bim and CAD under the current background
After route link navigation, the sub page does not display the navigation style problem
Plato Farm元宇宙IEO上线四大,链上交易颇高
【问题解决】‘ascii‘ codec can‘t encode characters in position xx-xx: ordinal not in range(128)