unique_id_dao.go 736 字节
package dao

import (
	"fmt"
	pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
)

type UniqueIdDao struct {
	transactionContext *pgTransaction.TransactionContext
}

func (d *UniqueIdDao) GenerateUniqueId() (int, error) {
	sql := " SELECT nextval('manufacture.manufacture_seq_id_seq') id;"
	var data = struct {
		Id int
	}{}
	_, err := d.transactionContext.PgTx.Query(&data, sql)
	if err != nil {
		return 0, err
	}
	return data.Id, nil
}

func NewUniqueIdDao(transactionContext *pgTransaction.TransactionContext) (*UniqueIdDao, error) {
	if transactionContext == nil {
		return nil, fmt.Errorf("transactionContext参数不能为nil")
	} else {
		return &UniqueIdDao{
			transactionContext: transactionContext,
		}, nil
	}
}