cockroach

package
v0.0.0-...-af8e841 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 10, 2025 License: Apache-2.0 Imports: 14 Imported by: 7

Documentation

Index

Constants

View Source
const (
	EnvLocalRegion = "LOCAL_REGION"
	EnvBaseBalance = "BASE_BALANCE"
)
View Source
const (
	BaseUnit           = 1_000_000
	MinBalance         = 10 * BaseUnit
	DefaultBaseBalance = 5 * BaseUnit
)

Variables

View Source
var (
	BaseBalance = int64(DefaultBaseBalance)
)
View Source
var ErrInsufficientBalance = errors.New("insufficient balance")

Functions

func CreateTableIfNotExist

func CreateTableIfNotExist(db *gorm.DB, tables ...interface{}) error

func HandleUpdateResult

func HandleUpdateResult(result *gorm.DB, entityName string) error

Types

type Cockroach

type Cockroach struct {
	DB          *gorm.DB
	Localdb     *gorm.DB
	LocalRegion *types.Region
	ZeroAccount *types.Account
	// contains filtered or unexported fields
}

func NewCockRoach

func NewCockRoach(globalURI, localURI string) (*Cockroach, error)

func (*Cockroach) AddBalance

func (c *Cockroach) AddBalance(ops *types.UserQueryOpts, amount int64) error

func (*Cockroach) AddDeductionBalance

func (c *Cockroach) AddDeductionBalance(ops *types.UserQueryOpts, amount int64) error

func (*Cockroach) AddDeductionBalanceWithDB

func (c *Cockroach) AddDeductionBalanceWithDB(ops *types.UserQueryOpts, amount int64, tx *gorm.DB) error

func (*Cockroach) AddDeductionBalanceWithFunc

func (c *Cockroach) AddDeductionBalanceWithFunc(ops *types.UserQueryOpts, amount int64, preDo, postDo func() error) error

func (*Cockroach) AddRewardBalance

func (c *Cockroach) AddRewardBalance(ops *types.UserQueryOpts, amount int64, db *gorm.DB) error

func (*Cockroach) Close

func (c *Cockroach) Close() error

Close db connection

func (*Cockroach) CreateAccount

func (c *Cockroach) CreateAccount(ops *types.UserQueryOpts, account *types.Account) (*types.Account, error)

func (*Cockroach) CreateInvoicePaymentsWithDB

func (c *Cockroach) CreateInvoicePaymentsWithDB(invoicePayments []types.InvoicePayment, DB *gorm.DB) error

create invoicePayments

func (*Cockroach) CreateInvoiceWithDB

func (c *Cockroach) CreateInvoiceWithDB(i *types.Invoice, DB *gorm.DB) error

func (*Cockroach) CreateRegion

func (c *Cockroach) CreateRegion(region *types.Region) error

func (*Cockroach) CreateUser

func (c *Cockroach) CreateUser(oAuth *types.OauthProvider, regionUserCr *types.RegionUserCr, user *types.User, workspace *types.Workspace, userWorkspace *types.UserWorkspace) error

func (*Cockroach) GetAccount

func (c *Cockroach) GetAccount(ops *types.UserQueryOpts) (*types.Account, error)

func (*Cockroach) GetAccountConfig

func (c *Cockroach) GetAccountConfig() (types.AccountConfig, error)

func (*Cockroach) GetAccountWithWorkspace

func (c *Cockroach) GetAccountWithWorkspace(workspace string) (*types.Account, error)

func (*Cockroach) GetGiftCodeWithCode

func (c *Cockroach) GetGiftCodeWithCode(code string) (*types.GiftCode, error)

func (*Cockroach) GetInvoice

func (c *Cockroach) GetInvoice(userID string, req types.LimitReq) ([]types.Invoice, types.LimitResp, error)

func (*Cockroach) GetInvoicePayments

func (c *Cockroach) GetInvoicePayments(invoiceID string) ([]types.InvoicePayment, error)

func (*Cockroach) GetInvoiceWithID

func (c *Cockroach) GetInvoiceWithID(invoiceID string) (*types.Invoice, error)

GetInvoiceWithID

func (*Cockroach) GetLocalRegion

func (c *Cockroach) GetLocalRegion() types.Region

func (*Cockroach) GetPayment

func (c *Cockroach) GetPayment(ops *types.UserQueryOpts, startTime, endTime time.Time) ([]types.Payment, error)

func (*Cockroach) GetPaymentWithID

func (c *Cockroach) GetPaymentWithID(paymentID string) (*types.Payment, error)

func (*Cockroach) GetPaymentWithInvoice

func (c *Cockroach) GetPaymentWithInvoice(invoiceID string) ([]types.Payment, error)

func (*Cockroach) GetPaymentWithLimit

func (c *Cockroach) GetPaymentWithLimit(ops *types.UserQueryOpts, req types.LimitReq, invoiced *bool) ([]types.Payment, types.LimitResp, error)

func (*Cockroach) GetRegions

func (c *Cockroach) GetRegions() ([]types.Region, error)

func (*Cockroach) GetTransfer

func (c *Cockroach) GetTransfer(ops *types.GetTransfersReq) (*types.GetTransfersResp, error)

func (*Cockroach) GetUnInvoicedPaymentListWithIds

func (c *Cockroach) GetUnInvoicedPaymentListWithIds(ids []string) ([]types.Payment, error)

func (*Cockroach) GetUser

func (c *Cockroach) GetUser(ops *types.UserQueryOpts) (*types.User, error)

func (*Cockroach) GetUserCr

func (c *Cockroach) GetUserCr(ops *types.UserQueryOpts) (*types.RegionUserCr, error)

func (*Cockroach) GetUserOauthProvider

func (c *Cockroach) GetUserOauthProvider(ops *types.UserQueryOpts) ([]types.OauthProvider, error)

func (*Cockroach) GetUserRealNameInfoByUserID

func (c *Cockroach) GetUserRealNameInfoByUserID(userID string) (*types.UserRealNameInfo, error)

func (*Cockroach) GetUserRechargeDiscount

func (c *Cockroach) GetUserRechargeDiscount(ops *types.UserQueryOpts) (types.UserRechargeDiscount, error)

func (*Cockroach) GetUserUID

func (c *Cockroach) GetUserUID(ops *types.UserQueryOpts) (uuid.UUID, error)

func (*Cockroach) GetWorkspace

func (c *Cockroach) GetWorkspace(namespaces ...string) ([]types.Workspace, error)

func (*Cockroach) InitTables

func (c *Cockroach) InitTables() error

func (*Cockroach) InsertAccountConfig

func (c *Cockroach) InsertAccountConfig(config *types.AccountConfig) error

func (*Cockroach) IsNullRecharge

func (c *Cockroach) IsNullRecharge(ops *types.UserQueryOpts) (bool, error)

func (*Cockroach) NewAccount

func (c *Cockroach) NewAccount(ops *types.UserQueryOpts) (*types.Account, error)

NewAccount create a new account

func (*Cockroach) Payment

func (c *Cockroach) Payment(payment *types.Payment) error

func (*Cockroach) ProcessPendingTaskRewards

func (c *Cockroach) ProcessPendingTaskRewards() error

func (*Cockroach) ReduceBalance

func (c *Cockroach) ReduceBalance(ops *types.UserQueryOpts, amount int64) error

func (*Cockroach) ReduceDeductionBalance

func (c *Cockroach) ReduceDeductionBalance(ops *types.UserQueryOpts, amount int64) error

func (*Cockroach) SavePayment

func (c *Cockroach) SavePayment(payment *types.Payment) error

func (*Cockroach) SetAccountCreateLocalRegion

func (c *Cockroach) SetAccountCreateLocalRegion(account *types.Account, region string) error

func (*Cockroach) SetInvoiceStatus

func (c *Cockroach) SetInvoiceStatus(ids []string, stats string) error

func (*Cockroach) SetPaymentInvoice

func (c *Cockroach) SetPaymentInvoice(ops *types.UserQueryOpts, paymentIDList []string) error

func (*Cockroach) SetPaymentInvoiceWithDB

func (c *Cockroach) SetPaymentInvoiceWithDB(ops *types.UserQueryOpts, paymentIDList []string, DB *gorm.DB) error

func (*Cockroach) TransferAccount

func (c *Cockroach) TransferAccount(from, to *types.UserQueryOpts, amount int64) error

func (*Cockroach) TransferAccountAll

func (c *Cockroach) TransferAccountAll(from, to *types.UserQueryOpts) error

func (*Cockroach) UseGiftCode

func (c *Cockroach) UseGiftCode(giftCode *types.GiftCode, userID string) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL