本文整理汇总了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
}
开发者ID:intelsdi-x,项目名称:rkt,代码行数:57,代码来源:migrate_test.go
示例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
}
开发者ID:yanghongkjxy,项目名称:rkt,代码行数:56,代码来源:migrate_test.go
示例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
}
开发者ID:intelsdi-x,项目名称:rkt,代码行数:20,代码来源:migrate_test.go
注:本文中的github.com/coreos/rkt/store/db.DB类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论