当前位置: 首页>>代码示例>>Golang>>正文


Golang DbMap.SelectNullInt方法代码示例

本文整理汇总了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
}
开发者ID:DaleWebb,项目名称:readraptor,代码行数:23,代码来源:article.go

示例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
}
开发者ID:DaleWebb,项目名称:readraptor,代码行数:23,代码来源:read_receipt.go

示例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
}
开发者ID:DaleWebb,项目名称:readraptor,代码行数:23,代码来源:reader.go

示例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
}
开发者ID:DaleWebb,项目名称:readraptor,代码行数:54,代码来源:read_receipt.go


注:本文中的github.com/coopernurse/gorp.DbMap.SelectNullInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。