本文整理匯總了Golang中github.com/coopernurse/gorp.DbMap.SelectNullInt方法的典型用法代碼示例。如果您正苦於以下問題:Golang DbMap.SelectNullInt方法的具體用法?Golang DbMap.SelectNullInt怎麽用?Golang DbMap.SelectNullInt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/coopernurse/gorp.DbMap
的用法示例。
在下文中一共展示了DbMap.SelectNullInt方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: UpsertArticle
func UpsertArticle(dbmap *gorp.DbMap, accountId int64, key string) (int64, error) {
id, err := dbmap.SelectNullInt(`
with s as (
update articles set updated_at = $3 where account_id = $1 and key = $2 returning id
), i as (
insert into articles ("account_id", "key", "created_at", "updated_at")
select $1, $2, $3, $3
where not exists (select 1 from s)
returning id
)
select id from i union all select id from s;
`, accountId,
key,
time.Now().UTC(),
)
if err != nil {
return -1, err
}
iid, err := id.Value()
return iid.(int64), err
}
示例2: InsertExpectedReader
func InsertExpectedReader(dbmap *gorp.DbMap, aid, rid int64) (int64, error) {
id, err := dbmap.SelectNullInt(`
with s as (
select id from read_receipts where article_id = $1 and reader_id = $2
), i as (
insert into read_receipts ("article_id", "reader_id", "created_at")
select $1, $2, $3
where not exists (select 1 from s)
returning id
)
select id from i union all select id from s;`,
aid,
rid,
time.Now().UTC(),
)
if err != nil {
return -1, err
}
iid, err := id.Value()
return iid.(int64), err
}
示例3: InsertReader
func InsertReader(dbmap *gorp.DbMap, accountId int64, distinctId string) (int64, error) {
id, err := dbmap.SelectNullInt(`
with s as (
select id from readers where account_id = $1 and distinct_id = $2
), i as (
insert into readers ("account_id", "distinct_id", "created_at")
select $1, $2, $3
where not exists (select 1 from s)
returning id
)
select id from i union all select id from s;
`, accountId,
distinctId,
time.Now().UTC(),
)
if err != nil {
return -1, err
}
iid, err := id.Value()
return iid.(int64), err
}
示例4: UpsertReadReceipt
func UpsertReadReceipt(dbmap *gorp.DbMap, articleId, readerId int64) (int64, error) {
defer UpdateArticleCounts(dbmap, articleId)
at := time.Now().UTC()
_, err := dbmap.SelectNullInt(`
update read_receipts set first_read_at = $1
where article_id=$2 and reader_id=$3 and first_read_at is null`,
at,
articleId,
readerId,
)
id, err := dbmap.SelectNullInt(`
update read_receipts set last_read_at = $1, read_count = read_count + 1
where article_id=$2 and reader_id=$3
returning id;
`, at,
articleId,
readerId,
)
if err != nil {
return -1, err
}
if id.Valid {
return id.Int64, nil
}
id, err = dbmap.SelectNullInt(`
with s as (
select id from read_receipts where article_id = $1 and reader_id = $2
), i as (
insert into read_receipts (
"article_id", "reader_id",
"created_at", "first_read_at", "last_read_at",
"read_count")
select $1, $2, $3, $3, $3, 1
where not exists (select 1 from s)
returning id
)
select id from i union all select id from s;
`, articleId,
readerId,
at,
)
if err != nil {
return 0, err
}
iid, err := id.Value()
if err != nil {
return 0, err
}
return iid.(int64), err
}