本文整理匯總了Golang中github.com/coreos/rkt/store/db.DB類的典型用法代碼示例。如果您正苦於以下問題:Golang DB類的具體用法?Golang DB怎麽用?Golang DB使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了DB類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: populateDBV2
func populateDBV2(db *db.DB, dbVersion int, aciInfos []*ACIInfoV0_2, remotes []*RemoteV2_7) error {
var dbCreateStmts = [...]string{
// version table
"CREATE TABLE IF NOT EXISTS version (version int);",
fmt.Sprintf("INSERT INTO version VALUES (%d)", dbVersion),
// remote table. The primary key is "aciurl".
"CREATE TABLE IF NOT EXISTS remote (aciurl string, sigurl string, etag string, blobkey string, cachemaxage int, downloadtime time);",
"CREATE UNIQUE INDEX IF NOT EXISTS aciurlidx ON remote (aciurl)",
// aciinfo table. The primary key is "blobkey" and it matches the key used to save that aci in the blob store
"CREATE TABLE IF NOT EXISTS aciinfo (blobkey string, appname string, importtime time, latest bool);",
"CREATE UNIQUE INDEX IF NOT EXISTS blobkeyidx ON aciinfo (blobkey)",
"CREATE INDEX IF NOT EXISTS appnameidx ON aciinfo (appname)",
}
fn := func(tx *sql.Tx) error {
for _, stmt := range dbCreateStmts {
_, err := tx.Exec(stmt)
if err != nil {
return err
}
}
return nil
}
if err := db.Do(fn); err != nil {
return err
}
fn = func(tx *sql.Tx) error {
for _, aciinfo := range aciInfos {
_, err := tx.Exec("INSERT into aciinfo values ($1, $2, $3, $4)", aciinfo.BlobKey, aciinfo.AppName, aciinfo.ImportTime, aciinfo.Latest)
if err != nil {
return err
}
}
return nil
}
if err := db.Do(fn); err != nil {
return err
}
fn = func(tx *sql.Tx) error {
for _, remote := range remotes {
_, err := tx.Exec("INSERT into remote values ($1, $2, $3, $4, $5, $6)", remote.ACIURL, remote.SigURL, remote.ETag, remote.BlobKey, remote.CacheMaxAge, remote.DownloadTime)
if err != nil {
return err
}
}
return nil
}
if err := db.Do(fn); err != nil {
return err
}
return nil
}
示例2: populateDBV6
func populateDBV6(db *db.DB, dbVersion int, aciInfos []*ACIInfoV6, remotes []*RemoteV2_6) error {
var dbCreateStmts = [...]string{
// version table
"CREATE TABLE IF NOT EXISTS version (version int);",
fmt.Sprintf("INSERT INTO version VALUES (%d)", dbVersion),
// remote table. The primary key is "aciurl".
"CREATE TABLE IF NOT EXISTS remote (aciurl string, sigurl string, etag string, blobkey string, cachemaxage int, downloadtime time);",
"CREATE UNIQUE INDEX IF NOT EXISTS aciurlidx ON remote (aciurl)",
// aciinfo table. The primary key is "blobkey" and it matches the key used to save that aci in the blob store
"CREATE TABLE IF NOT EXISTS aciinfo (blobkey string, name string, importtime time, lastused time, latest bool, size int64, treestoresize int64, insecureoptions int64 DEFAULT 0);",
"CREATE UNIQUE INDEX IF NOT EXISTS blobkeyidx ON aciinfo (blobkey)",
"CREATE INDEX IF NOT EXISTS nameidx ON aciinfo (name)",
}
fn := func(tx *sql.Tx) error {
for _, stmt := range dbCreateStmts {
_, err := tx.Exec(stmt)
if err != nil {
return err
}
}
return nil
}
if err := db.Do(fn); err != nil {
return err
}
fn = func(tx *sql.Tx) error {
for _, aciinfo := range aciInfos {
_, err := tx.Exec("INSERT INTO aciinfo (blobkey, name, importtime, lastused, latest, size, treestoresize, souceurl, insecureoptions) VALUES ($1, $2, $3, $4, $5, $6, $7, $8)", aciinfo.BlobKey, aciinfo.Name, aciinfo.ImportTime, aciinfo.LastUsed, aciinfo.Latest, aciinfo.Size, aciinfo.TreeStoreSize, aciinfo.InsecureOptions)
if err != nil {
return err
}
}
return nil
}
if err := db.Do(fn); err != nil {
return err
}
fn = func(tx *sql.Tx) error {
for _, remote := range remotes {
_, err := tx.Exec("INSERT into remote values ($1, $2, $3, $4, $5, $6)", remote.ACIURL, remote.SigURL, remote.ETag, remote.BlobKey, remote.CacheMaxAge, remote.DownloadTime)
if err != nil {
return err
}
}
return nil
}
if err := db.Do(fn); err != nil {
return err
}
return nil
}
示例3: load
// load populates the given struct with the data in db.
// the given struct d should be empty
func (d *DBV0) load(db *db.DB) error {
fn := func(tx *sql.Tx) error {
var err error
d.aciinfos, err = getAllACIInfosV0_2(tx)
if err != nil {
return err
}
d.remotes, err = getAllRemoteV0_1(tx)
if err != nil {
return err
}
return nil
}
if err := db.Do(fn); err != nil {
return err
}
return nil
}