大佬教程收集整理的这篇文章主要介绍了godbc中使用mssql的小实例,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<pre name="code" class="plain">package main import ( "fmt" "github.com/go-xorm/xorm" _ "github.com/lunny/godbc" ) func main() { ENGIn,err := xorm.NewENGIne("odbc","driver={SQL Server};Server=127.0.0.1;Database=Test; uid=sa; pwd=123456;") if err != nil { fmt.Println("新建引擎",err) return } fmt.Println(ENGIn.Ping()) }
package xorm import ( "database/sql" "tesTing" _ "github.com/lunny/godbc" ) const mssqlConnStr = "driver={SQL Server};Server=192.168.20.135;Database=xorm_test; uid=sa; pwd=1234;" func newMssqlENGIne() (*ENGIne,error) { return NewENGIne("odbc",mssqlConnStr) } func Testmssql(t *tesTing.T) { ENGIne,err := newMssqlENGIne() defer ENGIne.Close() if err != nil { t.Error(err) return } ENGIne.ShowSQL = showTestSql ENGIne.ShowErr = showTestSql ENGIne.ShowWarn = showTestSql ENGIne.ShowDebug = showTestSql testAll(ENGIne,t) testAll2(ENGIne,t) } func TestmssqlWithCache(t *tesTing.T) { ENGIne,err := newMssqlENGIne() defer ENGIne.Close() if err != nil { t.Error(err) return } ENGIne.SetDefaultCacher(NewLRUCacher(NewMemoryStore(),1000)) ENGIne.ShowSQL = showTestSql ENGIne.ShowErr = showTestSql ENGIne.ShowWarn = showTestSql ENGIne.ShowDebug = showTestSql testAll(ENGIne,t) } func newMssqlDriverDB() (*sql.DB,error) { return sql.open("odbc",mssqlConnStr) } const ( createTableMssql = `IF NOT EXISTS (SELECT [name] FROM sys.tables WHERE [name] = 'big_struct' ) create table "big_struct" ("id" BIGINT PRIMary KEY IDENTITY NOT NULL,"name" VARCHAR(255) NULL,"title" VARCHAR(255) NULL,"age" VARCHAR(255) NULL,"alias" VARCHAR(255) NULL,"nick_name" VARCHAR(255) null); ` dropTableMssql = "IF EXISTS (SELECT * FROM sysobjects WHERE id = object_id(N'big_struct') and OBjeCTPROPERTY(id,N'IsUserTable') = 1) drop table IF EXISTS `big_struct`;" ) func BenchmarkMssqlDriverInsert(t *tesTing.b) { doBenchDriver(newMssqlDriverDB,createTableMssql,dropTableMssql,doBenchDriverInsert,t) } func BenchmarkMssqlDriverFind(t *tesTing.b) { doBenchDriver(newMssqlDriverDB,doBenchDriverFind,t) } func BenchmarkMssqlNoCacheInsert(t *tesTing.b) { ENGIne,err := newMssqlENGIne() defer ENGIne.Close() if err != nil { t.Error(err) return } //ENGIne.ShowSQL = true doBenchInsert(ENGIne,t) } func BenchmarkMssqlNoCacheFind(t *tesTing.b) { ENGIne,err := newMssqlENGIne() defer ENGIne.Close() if err != nil { t.Error(err) return } //ENGIne.ShowSQL = true doBenchFind(ENGIne,t) } func BenchmarkMssqlNoCacheFindPtr(t *tesTing.b) { ENGIne,err := newMssqlENGIne() defer ENGIne.Close() if err != nil { t.Error(err) return } //ENGIne.ShowSQL = true doBenchFindPtr(ENGIne,t) } func BenchmarkMssqlCacheInsert(t *tesTing.b) { ENGIne,1000)) doBenchInsert(ENGIne,t) } func BenchmarkMssqlCacheFind(t *tesTing.b) { ENGIne,1000)) doBenchFind(ENGIne,t) } func BenchmarkMssqlCacheFindPtr(t *tesTing.b) { ENGIne,1000)) doBenchFindPtr(ENGIne,t) }
以上是大佬教程为你收集整理的godbc中使用mssql的小实例全部内容,希望文章能够帮你解决godbc中使用mssql的小实例所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。