本文整理汇总了Golang中github.com/boourns/dbutil.DBLike类的典型用法代码示例。如果您正苦于以下问题:Golang DBLike类的具体用法?Golang DBLike怎么用?Golang DBLike使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DBLike类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: CreateDriveTable
func CreateDriveTable(tx dbutil.DBLike) error {
stmt, err := tx.Prepare(`
CREATE TABLE Drive (
ID INTEGER PRIMARY KEY,
Name VARCHAR(255),
SerialNumber VARCHAR(255)
);
`)
if err != nil {
return err
}
_, err = stmt.Exec()
if err != nil {
return err
}
return nil
}
示例2: Delete
func (s *Drive) Delete(tx dbutil.DBLike) error {
stmt, err := tx.Prepare("DELETE FROM Drive WHERE ID = ?")
if err != nil {
return err
}
_, err = stmt.Exec(s.ID)
if err != nil {
return err
}
return nil
}
示例3: Insert
func (s *Drive) Insert(tx dbutil.DBLike) error {
stmt, err := tx.Prepare("INSERT INTO Drive(Name,SerialNumber) VALUES(?,?)")
if err != nil {
return err
}
result, err := stmt.Exec(s.Name, s.SerialNumber)
if err != nil {
return err
}
s.ID, err = result.LastInsertId()
if err != nil {
return err
}
return nil
}
示例4: Update
func (s *Drive) Update(tx dbutil.DBLike) error {
stmt, err := tx.Prepare(fmt.Sprintf("UPDATE Drive(%s) VALUES(?,?,?) WHERE Drive.ID = ?", sqlFieldsForDrive()))
if err != nil {
return err
}
params := []interface{}{s.ID, s.Name, s.SerialNumber}
params = append(params, s.ID)
_, err = stmt.Exec(params...)
if err != nil {
return err
}
return nil
}
示例5: Select
func Select(tx dbutil.DBLike, cond string, condFields ...interface{}) ([]*Drive, error) {
ret := []*Drive{}
sql := fmt.Sprintf("SELECT %s from Drive %s", sqlFieldsForDrive(), cond)
rows, err := tx.Query(sql, condFields...)
if err != nil {
return nil, err
}
for rows.Next() {
item, err := loadDrive(rows)
if err != nil {
return nil, err
}
ret = append(ret, item)
}
rows.Close()
return ret, nil
}
示例6: Insert
func (s *File) Insert(tx dbutil.DBLike) error {
stmt, err := tx.Prepare("INSERT INTO File(DriveID,Path,Hash,Thumbnail,Size,CreatedAt,ToBeDeleted) VALUES(?,?,?,?,?,?,?)")
if err != nil {
return err
}
result, err := stmt.Exec(s.DriveID, s.Path, s.Hash, s.Thumbnail, s.Size, s.CreatedAt, s.ToBeDeleted)
if err != nil {
return err
}
s.ID, err = result.LastInsertId()
if err != nil {
return err
}
return nil
}
示例7: Update
func (s *File) Update(tx dbutil.DBLike) error {
stmt, err := tx.Prepare(fmt.Sprintf("UPDATE File(%s) VALUES(?,?,?,?,?,?,?,?) WHERE File.ID = ?", sqlFieldsForFile()))
if err != nil {
return err
}
params := []interface{}{s.ID, s.DriveID, s.Path, s.Hash, s.Thumbnail, s.Size, s.CreatedAt, s.ToBeDeleted}
params = append(params, s.ID)
_, err = stmt.Exec(params...)
if err != nil {
return err
}
return nil
}
示例8: CreateFileTable
func CreateFileTable(tx dbutil.DBLike) error {
stmt, err := tx.Prepare(`
CREATE TABLE File (
ID INTEGER PRIMARY KEY,
DriveID INTEGER,
Path VARCHAR(255),
Hash VARCHAR(255),
Thumbnail VARCHAR(255),
Size INTEGER,
CreatedAt DATETIME,
ToBeDeleted BOOLEAN
);
`)
if err != nil {
return err
}
_, err = stmt.Exec()
if err != nil {
return err
}
return nil
}