本文整理汇总了Golang中database/sql.Register函数的典型用法代码### 示例。如果您正苦于以下问题:Golang Register函数的具体用法?Golang Register怎么用?Golang Register使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。
在下文中一共展示了Register函数的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。
示例1: OpenFromConnPool
// OpenFromConnPool takes the existing *pgx.ConnPool pool and returns a *sql.DB
// with pool as the backend. This enables full control over the connection
// process and configuration while maintaining compatibility with the
// database/sql interface. In addition, by calling Driver() on the returned
// *sql.DB and typecasting to *stdlib.Driver a reference to the pgx.ConnPool can
// be reaquired later. This allows fast paths targeting pgx to be used while
// still maintaining compatibility with other databases and drivers.
//
// pool connection size must be at least 2.
func OpenFromConnPool(pool *pgx.ConnPool) (*sql.DB, error) {
d := &Driver{Pool: pool}
name := fmt.Sprintf("pgx-%d", openFromConnPoolCount)
openFromConnPoolCount++
sql.Register(name, d)
db, err := sql.Open(name, "")
if err != nil {
return nil, err
}
// Presumably OpenFromConnPool is being used because the user wants to use
// database/sql most of the time, but fast path with pgx some of the time.
// Allow database/sql to use all the connections, but release 2 idle ones.
// Don't have database/sql immediately release all idle connections because
// that would mean that prepared statements would be lost (which kills
// performance if the prepared statements constantly have to be reprepared)
stat := pool.Stat()
if stat.MaxConnections <= 2 {
return nil, errors.New("pool connection size must be at least 2")
}
db.SetMaxIdleConns(stat.MaxConnections - 2)
db.SetMaxOpenConns(stat.MaxConnections)
return db, nil
}
开发者ID:jonasi,项目名称:pgx,代码行数:35,代码来源:sql.go
示例2: init
func init() {
mu.Lock()
defer mu.Unlock()
if !driverRegistered("mysql") {
sql.Register("mysql", &mysql.MySQLDriver{})
}
if !driverRegistered("mariadb") {
sql.Register("mariadb", &mysql.MySQLDriver{})
}
}
开发者ID:wawandco,项目名称:transporter,代码行数:12,代码来源:migrator.go
示例3: init
// init computes the supported versions into a byte slice and register the driver.
func init() {
for i, v := range versionsSupported {
binary.BigEndian.PutUint32(handshakeRequest[i*4:i*4+4], v)
}
sql.Register("neo4j-bolt", &neoDriver{})
}
开发者ID:yolii,项目名称:neoql,代码行数:8,代码来源:driver.go
示例4: initDatabase
func initDatabase() models.Control {
var dbDriver string
sql.Register(dbDriver, &sqlite3.SQLiteDriver{})
database, err := sql.Open(dbDriver, "db")
if err != nil {
fmt.Println("Failed to create the handle")
}
if err := database.Ping(); err != nil {
fmt.Println("Failed to keep connection alive")
}
if err != nil {
log.Fatal(err)
}
_, err = database.Exec(
"CREATE TABLE IF NOT EXISTS Config (id integer PRIMARY KEY, notifications_limit integer NOT NULL, timeout integer NOT NULL)",
)
if err != nil {
log.Fatal(err)
}
config := models.Config{NotificationsLimit: 3, Timeout: 10}
_ = database.QueryRow(
"SELECT notifications_limit, timeout FROM Config ORDER BY id DESC LIMIT 1",
).Scan(&config.NotificationsLimit, &config.Timeout)
controller := models.Control{Config: config, Database: database}
return controller
}
开发者ID:dorumd,项目名称:go-osx-email-notifications,代码行数:34,代码来源:client.go
示例5: main
func main() {
// Load and validate config file.
config := LoadConfig("config.json")
// Register SQLite driver.
sqlite3conn := []*sqlite3.SQLiteConn{}
sql.Register(config.DbName,
&sqlite3.SQLiteDriver{
ConnectHook: func(conn *sqlite3.SQLiteConn) error {
sqlite3conn = append(sqlite3conn, conn)
return nil
},
})
// Open SQLite database and assign it to the contxt.
db, err := sql.Open(config.DbName, config.DbPath)
if err != nil {
log.Fatal(err.Error())
}
// Create the application context.
ctx := server.NewAppContext(db, config.AuthKey)
defer db.Close()
// Create mux and register the handlers.
mux := http.NewServeMux()
mux.Handle("/gcm/devices/", server.NewGCMHandler(ctx))
mux.Handle("/apn/devices/", server.NewAPNHandler(ctx))
// Attemp to start the server.
address := fmt.Sprintf("%s:%d", config.Address, config.Port)
log.Fatal(http.ListenAndServe(address, mux))
}
开发者ID:contactlab,项目名称:CLABPush-Go,代码行数:34,代码来源:main.go
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng