当前位置:网站首页>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
边栏推荐
- SIGIR'22 "Microsoft" CTR estimation: using context information to promote feature representation learning
- R language uses the preprocess function of caret package for data preprocessing: BoxCox transform all data columns (convert non normal distribution data columns to normal distribution data and can not
- 微信中金财富高端专区安全吗,证券如何开户呢
- Shanghai a répondu que « le site officiel de la farine est illégal »: l'exploitation et l'entretien négligents ont été « noirs » et la police a déposé une plainte
- LeetCode 1346、检查整数及其两倍数是否存在
- selenium.common.exceptions.WebDriverException: Message: ‘chromedriver‘ executable needs to be in PAT
- How about CICC fortune? Is it safe to open an account
- Wave field Dao new species end up, how does usdd break the situation and stabilize the currency market?
- Installation and use of NVM
- BMP JPEG 图片转换为矢量图像 ContourTrace
猜你喜欢

Commit and rollback in DCL of 16 MySQL

LeetCode 542、01 矩阵

Five minutes to show you what JWT is

JDBC tool class jdbcfiledateutil uploads files and date format conversion, including the latest, simplest and easiest way to upload single files and multiple files

Numpy Index & slice & iteration

Fundamentals of network communication (LAN, Wan, IP address, port number, protocol, encapsulation and distribution)

LeetCode 994、腐烂的橘子

How to protect ECs from hacker attacks?
Handwritten Google's first generation distributed computing framework MapReduce

Mysql database backup scheme
随机推荐
Handwritten Google's first generation distributed computing framework MapReduce
WordPress plug-in: WP CHINA Yes solution to slow domestic access to the official website
【问题解决】‘ascii‘ codec can‘t encode characters in position xx-xx: ordinal not in range(128)
[problem solving] 'ASCII' codec can't encode characters in position XX XX: ordinal not in range (128)
R language uses the preprocess function of caret package for data preprocessing: BoxCox transform all data columns (convert non normal distribution data columns to normal distribution data and can not
【PTA】L1-006 连续因子
Matlab analytic hierarchy process to quickly calculate the weight
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
Leetcode dynamic planning training camp (1-5 days)
Devexpress 14.1 installation record
DTMF双音多频信号仿真演示系统
Mathematical modeling column | Part 5: MATLAB optimization model solving method (Part I): Standard Model
考研英语唐叔的语法课笔记
Unity 模型整体更改材质
Numpy mathematical function & logical function
論文寫作 19: 會議論文與期刊論文的區別
Sqoop imports tinyint type fields to boolean type
Don't bother tensorflow learning notes (10-12) -- Constructing a simple neural network and its visualization
PostgreSQL basic functions
16MySQL之DCL 中 COMMIT和ROllBACK