本文整理汇总了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
}