当前位置: 首页 > 工具软件 > Go GORM > 使用案例 >

golang gorm query

寇景明
2023-12-01
// Get first record, order by primary key
db.First(&user)
 SELECT * FROM users ORDER BY id LIMIT 1;

// Get one record, no specfied order
db.Take(&user)
 SELECT * FROM users LIMIT 1;

// Get last record, order by primary key
db.Last(&user)
 SELECT * FROM users ORDER BY id DESC LIMIT 1;

// Get all records
db.Find(&users)
 SELECT * FROM users;

// Get record with primary key (only works for integer primary key)
db.First(&user, 10)
 SELECT * FROM users WHERE id = 10;
 类似资料:

相关阅读

相关文章

相关问答