package main
import (
"fmt" _ "github.com/go-sql-driver/mysql" "github.com/go-xorm/core" "github.com/go-xorm/xorm" "time")type Member struct {
Memberid int64 `xorm:"int(10) pk not null autoincr 'member_id'"` Member_name string `xorm:"char(50) not null"` Member_pwd string `xorm:"char(32) not null"` Member_count int64 `xorm:"smallint(6) not null default 0 "` Member_ok string `xorm:"varchar(50) not null"` Member_del int64 `xorm:"bigint(1) not null default 0 "` Member_email string `xorm:"varchar(40) not null"` Member_logintime time.Time `xorm:"updated"` Member_createtime int64 `xorm:"int(11) not null default 0"` Member_updatetime int64 `xorm:"int(11) not null default 0"` Member_ip string `xorm:"varchar(40) not null"` Member_version int64 `xorm:"version"`}var (
engine *xorm.Engine)func main() {
//数据库连接参数 params := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8&parseTime=true", "root", "root", "localhost:3306", "go") var err error //连接数据库 engine, err = xorm.NewEngine("mysql", params) if err != nil { panic(err) } //添加统一前缀 tbMapper := core.NewPrefixMapper(core.SnakeMapper{}, "go_") engine.SetTableMapper(tbMapper) defer engine.Close()member := new(Member)
//删除单条数据 dres, derr := engine.Where("member_id = ?", 1).Delete(member) if derr != nil { panic(derr) } fmt.Println(dres)//删除表
dterr := engine.DropTables(member) if dterr != nil { panic(dterr) }}
【版权申明】未经博主同意,谢绝转载!(请尊重原创,博主保留追究权) http://www.cnblogs.com/facetwitter/p/7595534.html