当前位置:网站首页>Gorm-- search you don't know
Gorm-- search you don't know
2022-06-25 13:28:00 【Favorite truffle chocolate】
db.Table("hello").Find(&user{})
db.First(&user{},"code=?","l2222")
db.Select("name, age").Find(&users) //Find Print results will be brought out
db.Model(&user{}).Update("CreatedAt",time.Now())
db.Order("age desc").Order("name").Find(&users)
db.Model(&User{}).Where("name = ?", "jinzhu").Count(&count)contain :
// User Contains a CreditCard, UserID For foreign key
type User struct {
gorm.Model
CreditCard CreditCard
}
type CreditCard struct {
gorm.Model
UserID uint
Number string
}
var card CreditCard
var user User
db.Model(&user).Related(&card, "CreditCard")
SELECT * FROM credit_cards WHERE user_id = 123; // 123 is user's primary key
// CreditCard yes user Field name of , That means getting user Of CreditCard Relationships and populates them into variables
// If the field name is the same as the type name of the variable , As shown in the example above , It can be omitted , Such as :
db.Model(&user).Related(&card)边栏推荐
- About data storage in memory
- 字符串各操作函数与内存函数详解
- Discuz仿今日头条模板/Discuz新闻资讯商业版GBK模板
- Explication d'un problème de manuel
- Sword finger offer II 029 Sorted circular linked list
- Germany holds global food security Solidarity Conference
- Used in time filter (EL table)
- Discuz copy today's headlines template /discuz news and information business GBK template
- Back test of quantitative trading - tqzfuturerenkowavestrategy
- Solution to Nacos' failure to modify the configuration file mysql8.0
猜你喜欢

leetcode:剑指 Offer II 091. 粉刷房子【二维dp】

The starting point for learning programming.

數據在內存中的存儲相關內容

Detailed explanation of string operation functions and memory functions

Configuring pytorch in win10 environment

Which Chinese virtual human is better? Sullivan, IDC: Xiaobing Baidu Shangtang ranks in the first echelon

【开源鸿蒙系统展示】RK3568开发板搭载OpenHarmony 3.1 Release

爱可可AI前沿推介(6.25)

“移动云杯”算力网络应用创新大赛火热报名中!

Summer Ending
随机推荐
Sword finger offer day 2 linked list (simple)
Storage related contents of data in memory
Intercept based on byte length
Cesium learning notes
Openstack learning notes -nova component insight
中国虚拟人哪家强?沙利文、IDC:小冰百度商汤位列第一梯队
Rust, le meilleur choix pour un programmeur de démarrer une entreprise?
##脚本编写ssh免密功能
J2EE from entry to earth 01 MySQL installation
Method for wrapping multiple promise instances into a new promise instance
Optimization of lazyagg query rewriting in parsing data warehouse
Explication d'un problème de manuel
Rust,程序員創業的最佳選擇?
An article clearly explains MySQL's clustering / Federation / coverage index, back to table, and index push down
Germany holds global food security Solidarity Conference
Analyse de l'optimisation de la réécriture des requêtes lazyagg de l'entrepôt
Prototype relationship between constructor and instance (1)
.NET in China - What's New in .NET
Deep parsing and implementation of redis stream advanced message queue [10000 words]
關於一道教材題的講解