go xorm增刪改查

1.增長session

若是傳入的bean不是完整的bean,而且傳入了地址,則調用結束後會被賦值
// InsertOne insert only one struct into database as a record.
// The in parameter bean must a struct or a point to struct. The return
// parameter is inserted and error
func (session *Session) InsertOne(bean interface{}) (int64, error) {

2.刪除it

不爲空的爲刪除條件io

// Delete records, bean's non-empty fields are conditions
func (session *Session) Delete(bean interface{}) (int64, error) {

3.修改table

第一個是更新的bean,不爲空則更新date

第二個是查找條件的bean,不爲空的爲條件map

// Update records, bean's non-empty fields are updated contents,
// condiBean' non-empty filds are conditions
// CAUTION:
// 1.bool will defaultly be updated content nor conditions
// You should call UseBool if you have bool to use.
// 2.float32 & float64 may be not inexact as conditions
func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int64, error)

4.查找float

返回一個記錄,不爲空的爲查找條件
// Get retrieve one record from database, bean's non-empty fields
// will be as conditions
func (session *Session) Get(bean interface{}) (bool, error) {

查找多條記錄
第一個參數是返回的列表,第二個爲查詢條件
// Find retrieve records from table, condiBeans's non-empty fields// are conditions. beans could be []Struct, []*Struct, map[int64]Struct// map[int64]*Structfunc (session *Session) Find(rowsSlicePtr interface{}, condiBean ...interface{}) error {
相關文章
相關標籤/搜索