nucleusdb

package
v0.4.58 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PqUniqueViolationCode = "23505"
)

Variables

This section is empty.

Functions

func BoolToInt16

func BoolToInt16(val bool) int16

func GetDbUrl

func GetDbUrl(cfg *ConnectConfig) string

func HandlePgxRollback

func HandlePgxRollback(ctx context.Context, tx PgxRollbackInterface, logger *slog.Logger)

Only logs if error is not ErrTxClosed

func HandleSqlRollback

func HandleSqlRollback(
	tx SqlRollbackInterface,
	logger *slog.Logger,
)

func Int16ToBool

func Int16ToBool(val int16) bool

func IsConflict

func IsConflict(err error) bool

func IsNoRows

func IsNoRows(err error) bool

func ToNullableString

func ToNullableString(text pgtype.Text) *string

func ToTimestamp

func ToTimestamp(value time.Time) (pgtype.Timestamp, error)

func ToUuid

func ToUuid(value string) (pgtype.UUID, error)

func UUIDString

func UUIDString(value pgtype.UUID) string

func UUIDStrings

func UUIDStrings(values []pgtype.UUID) []string

Types

type BaseDBTX

type BaseDBTX interface {
	Exec(context.Context, string, ...any) (pgconn.CommandTag, error)
	Query(context.Context, string, ...any) (pgx.Rows, error)
	QueryRow(context.Context, string, ...any) pgx.Row

	CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)
}

type ConnectConfig

type ConnectConfig struct {
	Host                  string
	Port                  int
	Database              string
	User                  string
	Pass                  string
	SslMode               *string
	MigrationsTableName   *string
	MigrationsTableQuoted *bool
	Options               *string
}

type CreateAccountApiKeyRequest

type CreateAccountApiKeyRequest struct {
	KeyName           string
	KeyValue          string
	AccountUuid       pgtype.UUID
	CreatedByUserUuid pgtype.UUID
	ExpiresAt         pgtype.Timestamp
}

type CreateJobConnectionDestination

type CreateJobConnectionDestination struct {
	ConnectionId pgtype.UUID
	Options      *pg_models.JobDestinationOptions
}

type DBTX

type DBTX interface {
	Begin(ctx context.Context) (pgx.Tx, error)
	BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error)
	Ping(ctx context.Context) error
	BaseDBTX
}

type MockDBTX

type MockDBTX struct {
	mock.Mock
}

MockDBTX is an autogenerated mock type for the DBTX type

func NewMockDBTX

func NewMockDBTX(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockDBTX

NewMockDBTX creates a new instance of MockDBTX. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockDBTX) Begin

func (_m *MockDBTX) Begin(ctx context.Context) (pgx.Tx, error)

Begin provides a mock function with given fields: ctx

func (*MockDBTX) BeginTx

func (_m *MockDBTX) BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error)

BeginTx provides a mock function with given fields: ctx, txOptions

func (*MockDBTX) CopyFrom

func (_m *MockDBTX) CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)

CopyFrom provides a mock function with given fields: ctx, tableName, columnNames, rowSrc

func (*MockDBTX) EXPECT

func (_m *MockDBTX) EXPECT() *MockDBTX_Expecter

func (*MockDBTX) Exec

func (_m *MockDBTX) Exec(_a0 context.Context, _a1 string, _a2 ...interface{}) (pgconn.CommandTag, error)

Exec provides a mock function with given fields: _a0, _a1, _a2

func (*MockDBTX) Ping

func (_m *MockDBTX) Ping(ctx context.Context) error

Ping provides a mock function with given fields: ctx

func (*MockDBTX) Query

func (_m *MockDBTX) Query(_a0 context.Context, _a1 string, _a2 ...interface{}) (pgx.Rows, error)

Query provides a mock function with given fields: _a0, _a1, _a2

func (*MockDBTX) QueryRow

func (_m *MockDBTX) QueryRow(_a0 context.Context, _a1 string, _a2 ...interface{}) pgx.Row

QueryRow provides a mock function with given fields: _a0, _a1, _a2

type MockDBTX_BeginTx_Call

type MockDBTX_BeginTx_Call struct {
	*mock.Call
}

MockDBTX_BeginTx_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'BeginTx'

func (*MockDBTX_BeginTx_Call) Return

func (_c *MockDBTX_BeginTx_Call) Return(_a0 pgx.Tx, _a1 error) *MockDBTX_BeginTx_Call

func (*MockDBTX_BeginTx_Call) Run

func (_c *MockDBTX_BeginTx_Call) Run(run func(ctx context.Context, txOptions pgx.TxOptions)) *MockDBTX_BeginTx_Call

func (*MockDBTX_BeginTx_Call) RunAndReturn

type MockDBTX_Begin_Call

type MockDBTX_Begin_Call struct {
	*mock.Call
}

MockDBTX_Begin_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Begin'

func (*MockDBTX_Begin_Call) Return

func (_c *MockDBTX_Begin_Call) Return(_a0 pgx.Tx, _a1 error) *MockDBTX_Begin_Call

func (*MockDBTX_Begin_Call) Run

func (_c *MockDBTX_Begin_Call) Run(run func(ctx context.Context)) *MockDBTX_Begin_Call

func (*MockDBTX_Begin_Call) RunAndReturn

func (_c *MockDBTX_Begin_Call) RunAndReturn(run func(context.Context) (pgx.Tx, error)) *MockDBTX_Begin_Call

type MockDBTX_CopyFrom_Call

type MockDBTX_CopyFrom_Call struct {
	*mock.Call
}

MockDBTX_CopyFrom_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CopyFrom'

func (*MockDBTX_CopyFrom_Call) Return

func (*MockDBTX_CopyFrom_Call) Run

func (_c *MockDBTX_CopyFrom_Call) Run(run func(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource)) *MockDBTX_CopyFrom_Call

func (*MockDBTX_CopyFrom_Call) RunAndReturn

type MockDBTX_Exec_Call

type MockDBTX_Exec_Call struct {
	*mock.Call
}

MockDBTX_Exec_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Exec'

func (*MockDBTX_Exec_Call) Return

func (*MockDBTX_Exec_Call) Run

func (_c *MockDBTX_Exec_Call) Run(run func(_a0 context.Context, _a1 string, _a2 ...interface{})) *MockDBTX_Exec_Call

func (*MockDBTX_Exec_Call) RunAndReturn

func (_c *MockDBTX_Exec_Call) RunAndReturn(run func(context.Context, string, ...interface{}) (pgconn.CommandTag, error)) *MockDBTX_Exec_Call

type MockDBTX_Expecter

type MockDBTX_Expecter struct {
	// contains filtered or unexported fields
}

func (*MockDBTX_Expecter) Begin

func (_e *MockDBTX_Expecter) Begin(ctx interface{}) *MockDBTX_Begin_Call

Begin is a helper method to define mock.On call

  • ctx context.Context

func (*MockDBTX_Expecter) BeginTx

func (_e *MockDBTX_Expecter) BeginTx(ctx interface{}, txOptions interface{}) *MockDBTX_BeginTx_Call

BeginTx is a helper method to define mock.On call

  • ctx context.Context
  • txOptions pgx.TxOptions

func (*MockDBTX_Expecter) CopyFrom

func (_e *MockDBTX_Expecter) CopyFrom(ctx interface{}, tableName interface{}, columnNames interface{}, rowSrc interface{}) *MockDBTX_CopyFrom_Call

CopyFrom is a helper method to define mock.On call

  • ctx context.Context
  • tableName pgx.Identifier
  • columnNames []string
  • rowSrc pgx.CopyFromSource

func (*MockDBTX_Expecter) Exec

func (_e *MockDBTX_Expecter) Exec(_a0 interface{}, _a1 interface{}, _a2 ...interface{}) *MockDBTX_Exec_Call

Exec is a helper method to define mock.On call

  • _a0 context.Context
  • _a1 string
  • _a2 ...interface{}

func (*MockDBTX_Expecter) Ping

func (_e *MockDBTX_Expecter) Ping(ctx interface{}) *MockDBTX_Ping_Call

Ping is a helper method to define mock.On call

  • ctx context.Context

func (*MockDBTX_Expecter) Query

func (_e *MockDBTX_Expecter) Query(_a0 interface{}, _a1 interface{}, _a2 ...interface{}) *MockDBTX_Query_Call

Query is a helper method to define mock.On call

  • _a0 context.Context
  • _a1 string
  • _a2 ...interface{}

func (*MockDBTX_Expecter) QueryRow

func (_e *MockDBTX_Expecter) QueryRow(_a0 interface{}, _a1 interface{}, _a2 ...interface{}) *MockDBTX_QueryRow_Call

QueryRow is a helper method to define mock.On call

  • _a0 context.Context
  • _a1 string
  • _a2 ...interface{}

type MockDBTX_Ping_Call

type MockDBTX_Ping_Call struct {
	*mock.Call
}

MockDBTX_Ping_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Ping'

func (*MockDBTX_Ping_Call) Return

func (_c *MockDBTX_Ping_Call) Return(_a0 error) *MockDBTX_Ping_Call

func (*MockDBTX_Ping_Call) Run

func (_c *MockDBTX_Ping_Call) Run(run func(ctx context.Context)) *MockDBTX_Ping_Call

func (*MockDBTX_Ping_Call) RunAndReturn

func (_c *MockDBTX_Ping_Call) RunAndReturn(run func(context.Context) error) *MockDBTX_Ping_Call

type MockDBTX_QueryRow_Call

type MockDBTX_QueryRow_Call struct {
	*mock.Call
}

MockDBTX_QueryRow_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'QueryRow'

func (*MockDBTX_QueryRow_Call) Return

func (*MockDBTX_QueryRow_Call) Run

func (_c *MockDBTX_QueryRow_Call) Run(run func(_a0 context.Context, _a1 string, _a2 ...interface{})) *MockDBTX_QueryRow_Call

func (*MockDBTX_QueryRow_Call) RunAndReturn

func (_c *MockDBTX_QueryRow_Call) RunAndReturn(run func(context.Context, string, ...interface{}) pgx.Row) *MockDBTX_QueryRow_Call

type MockDBTX_Query_Call

type MockDBTX_Query_Call struct {
	*mock.Call
}

MockDBTX_Query_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Query'

func (*MockDBTX_Query_Call) Return

func (_c *MockDBTX_Query_Call) Return(_a0 pgx.Rows, _a1 error) *MockDBTX_Query_Call

func (*MockDBTX_Query_Call) Run

func (_c *MockDBTX_Query_Call) Run(run func(_a0 context.Context, _a1 string, _a2 ...interface{})) *MockDBTX_Query_Call

func (*MockDBTX_Query_Call) RunAndReturn

func (_c *MockDBTX_Query_Call) RunAndReturn(run func(context.Context, string, ...interface{}) (pgx.Rows, error)) *MockDBTX_Query_Call

type MockTx

type MockTx struct {
	mock.Mock
}

MockTx is a mock type for the Tx interface

func (*MockTx) Begin

func (m *MockTx) Begin(ctx context.Context) (pgx.Tx, error)

func (*MockTx) Commit

func (m *MockTx) Commit(ctx context.Context) error

func (*MockTx) Conn

func (m *MockTx) Conn() *pgx.Conn

func (*MockTx) CopyFrom

func (m *MockTx) CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)

func (*MockTx) Exec

func (m *MockTx) Exec(ctx context.Context, sql string, arguments ...any) (pgconn.CommandTag, error)

func (*MockTx) LargeObjects

func (m *MockTx) LargeObjects() pgx.LargeObjects

func (*MockTx) Prepare

func (m *MockTx) Prepare(ctx context.Context, name, sql string) (*pgconn.StatementDescription, error)

func (*MockTx) Query

func (m *MockTx) Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error)

func (*MockTx) QueryRow

func (m *MockTx) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row

func (*MockTx) Rollback

func (m *MockTx) Rollback(ctx context.Context) error

func (*MockTx) SendBatch

func (m *MockTx) SendBatch(ctx context.Context, b *pgx.Batch) pgx.BatchResults

type NucleusDb

type NucleusDb struct {
	Db DBTX
	Q  db_queries.Querier
}

func New

func New(db DBTX, q db_queries.Querier) *NucleusDb

func NewFromConfig

func NewFromConfig(config *ConnectConfig) (*NucleusDb, error)

func (*NucleusDb) CreateAccountApikey

func (*NucleusDb) CreateJob

func (*NucleusDb) CreateTeamAccount

func (d *NucleusDb) CreateTeamAccount(
	ctx context.Context,
	userId pgtype.UUID,
	teamName string,
) (*db_queries.NeosyncApiAccount, error)

func (*NucleusDb) CreateTeamAccountInvite

func (d *NucleusDb) CreateTeamAccountInvite(
	ctx context.Context,
	accountId pgtype.UUID,
	userId pgtype.UUID,
	email string,
	expiresAt pgtype.Timestamp,
) (*db_queries.NeosyncApiAccountInvite, error)

func (*NucleusDb) SetPersonalAccount

func (d *NucleusDb) SetPersonalAccount(
	ctx context.Context,
	userId pgtype.UUID,
) (*db_queries.NeosyncApiAccount, error)

func (*NucleusDb) SetSourceSubsets added in v0.4.50

func (d *NucleusDb) SetSourceSubsets(
	ctx context.Context,
	jobId pgtype.UUID,
	schemas *mgmtv1alpha1.JobSourceSqlSubetSchemas,
	subsetByForeignKeyConstraints bool,
	userUuid pgtype.UUID,
) error

func (*NucleusDb) SetUserByAuthSub

func (d *NucleusDb) SetUserByAuthSub(
	ctx context.Context,
	authSub string,
) (*db_queries.NeosyncApiUser, error)

func (*NucleusDb) ValidateInviteAddUserToAccount

func (d *NucleusDb) ValidateInviteAddUserToAccount(
	ctx context.Context,
	userId pgtype.UUID,
	token string,
	userEmail string,
) (pgtype.UUID, error)

func (*NucleusDb) WithTx

func (d *NucleusDb) WithTx(
	ctx context.Context,
	opts *pgx.TxOptions,
	fn func(db BaseDBTX) error,
) error

type PgxRollbackInterface

type PgxRollbackInterface interface {
	Rollback(context.Context) error
}

type SqlRollbackInterface

type SqlRollbackInterface interface {
	Rollback() error
}

Jump to

Keyboard shortcuts

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