db

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BooksColumnsMock = []*gocql.ColumnMetadata{
	&gocql.ColumnMetadata{
		Name: "title",
		Kind: gocql.ColumnPartitionKey,
		Type: gocql.NewNativeType(0, gocql.TypeText, ""),
	},
	&gocql.ColumnMetadata{
		Name: "pages",
		Kind: gocql.ColumnRegular,
		Type: gocql.NewNativeType(0, gocql.TypeInt, ""),
	},
	&gocql.ColumnMetadata{
		Name: "first_name",
		Kind: gocql.ColumnRegular,
		Type: gocql.NewNativeType(0, gocql.TypeText, ""),
	},
	&gocql.ColumnMetadata{
		Name: "last_name",
		Kind: gocql.ColumnRegular,
		Type: gocql.NewNativeType(0, gocql.TypeText, ""),
	},
}

Functions

func NewDcInferringPolicy

func NewDcInferringPolicy() *dcInferringPolicy

func NewDefaultHostSelectionPolicy

func NewDefaultHostSelectionPolicy() gocql.HostSelectionPolicy

func NewKeyspaceMock

func NewKeyspaceMock(ksName string, tables map[string][]*gocql.ColumnMetadata) *gocql.KeyspaceMetadata

Types

type AlterTableAddInfo

type AlterTableAddInfo struct {
	Keyspace string
	Table    string
	ToAdd    []*gocql.ColumnMetadata
}

type AlterTableDropInfo

type AlterTableDropInfo struct {
	Keyspace string
	Table    string
	ToDrop   []string
}

type ColumnOrder

type ColumnOrder struct {
	Column string
	Order  string
}

type Config

type Config struct {
	Username   string
	Password   string
	SslOptions *SslOptions
}

type CreateKeyspaceInfo

type CreateKeyspaceInfo struct {
	Name        string
	DCReplicas  map[string]int
	IfNotExists bool
}

type CreateTableInfo

type CreateTableInfo struct {
	Keyspace       string
	Table          string
	PartitionKeys  []*gocql.ColumnMetadata
	ClusteringKeys []*gocql.ColumnMetadata
	Values         []*gocql.ColumnMetadata
	IfNotExists    bool
}

type Db

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

Db represents a connection to a db

func NewDb

func NewDb(config Config, hosts ...string) (*Db, error)

NewDb Gets a pointer to a db

func NewDbWithConnectedInstance

func NewDbWithConnectedInstance(session *gocql.Session) *Db

func NewDbWithSession

func NewDbWithSession(session Session) *Db

func (*Db) AlterTableAdd

func (db *Db) AlterTableAdd(info *AlterTableAddInfo, options *QueryOptions) error

func (*Db) AlterTableDrop

func (db *Db) AlterTableDrop(info *AlterTableDropInfo, options *QueryOptions) error

func (*Db) CreateKeyspace

func (db *Db) CreateKeyspace(info *CreateKeyspaceInfo, options *QueryOptions) error

func (*Db) CreateTable

func (db *Db) CreateTable(info *CreateTableInfo, options *QueryOptions) error

func (*Db) Delete

func (db *Db) Delete(info *DeleteInfo, options *QueryOptions) (ResultSet, error)

func (*Db) DropKeyspace

func (db *Db) DropKeyspace(info *DropKeyspaceInfo, options *QueryOptions) error

func (*Db) DropTable

func (db *Db) DropTable(info *DropTableInfo, options *QueryOptions) error

func (*Db) Execute

func (db *Db) Execute(query string, options *QueryOptions, values ...interface{}) (ResultSet, error)

func (*Db) ExecuteNoResult

func (db *Db) ExecuteNoResult(query string, options *QueryOptions, values ...interface{}) error

func (*Db) Insert

func (db *Db) Insert(info *InsertInfo, options *QueryOptions) (ResultSet, error)

func (*Db) Keyspace

func (db *Db) Keyspace(keyspace string) (*gocql.KeyspaceMetadata, error)

Keyspace Retrieves a keyspace

func (*Db) KeyspaceNamingInfo

func (db *Db) KeyspaceNamingInfo(ks *gocql.KeyspaceMetadata) config.KeyspaceNamingInfo

KeyspaceNamingInfo Retrieves the keyspace naming information

func (*Db) Keyspaces

func (db *Db) Keyspaces() ([]string, error)

Keyspaces Retrieves all the keyspace names

func (*Db) Select

func (db *Db) Select(info *SelectInfo, options *QueryOptions) (ResultSet, error)

func (*Db) Update

func (db *Db) Update(info *UpdateInfo, options *QueryOptions) (ResultSet, error)

func (*Db) Views

func (db *Db) Views(ksName string) (map[string]bool, error)

Views Retrieves all the views for the given keyspace

type DeleteInfo

type DeleteInfo struct {
	Keyspace    string
	Table       string
	Columns     []string
	QueryParams []interface{}
	IfCondition []types.ConditionItem
	IfExists    bool
}

type DropKeyspaceInfo

type DropKeyspaceInfo struct {
	Name     string
	IfExists bool
}

type DropTableInfo

type DropTableInfo struct {
	Keyspace string
	Table    string
	IfExists bool
}

type GoCqlSession

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

func (*GoCqlSession) ChangeSchema

func (session *GoCqlSession) ChangeSchema(query string, options *QueryOptions) error

func (*GoCqlSession) Execute

func (session *GoCqlSession) Execute(query string, options *QueryOptions, values ...interface{}) error

func (*GoCqlSession) ExecuteIter

func (session *GoCqlSession) ExecuteIter(query string, options *QueryOptions, values ...interface{}) (ResultSet, error)

func (*GoCqlSession) KeyspaceMetadata

func (session *GoCqlSession) KeyspaceMetadata(keyspaceName string) (*gocql.KeyspaceMetadata, error)

type InsertInfo

type InsertInfo struct {
	Keyspace    string
	Table       string
	Columns     []string
	QueryParams []interface{}
	IfNotExists bool
	TTL         int
}

type QueryOptions

type QueryOptions struct {
	UserOrRole        string
	Consistency       gocql.Consistency
	SerialConsistency gocql.SerialConsistency
	PageState         []byte
	PageSize          int
	Context           context.Context
}

func NewQueryOptions

func NewQueryOptions() *QueryOptions

func (*QueryOptions) WithConsistency

func (q *QueryOptions) WithConsistency(consistency gocql.Consistency) *QueryOptions

func (*QueryOptions) WithContext

func (q *QueryOptions) WithContext(ctx context.Context) *QueryOptions

func (*QueryOptions) WithPageSize

func (q *QueryOptions) WithPageSize(pageSize int) *QueryOptions

func (*QueryOptions) WithPageState

func (q *QueryOptions) WithPageState(pageState []byte) *QueryOptions

func (*QueryOptions) WithSerialConsistency

func (q *QueryOptions) WithSerialConsistency(serialConsistency gocql.SerialConsistency) *QueryOptions

func (*QueryOptions) WithUserOrRole

func (q *QueryOptions) WithUserOrRole(userOrRole string) *QueryOptions

type ResultMock

type ResultMock struct {
	mock.Mock
}

func (ResultMock) PageState

func (o ResultMock) PageState() []byte

func (ResultMock) Values

func (o ResultMock) Values() []map[string]interface{}

type ResultSet

type ResultSet interface {
	PageState() []byte
	Values() []map[string]interface{}
}

type SelectInfo

type SelectInfo struct {
	Keyspace string
	Table    string
	Where    []types.ConditionItem
	Options  *types.QueryOptions
	OrderBy  []ColumnOrder
}

type Session

type Session interface {
	// Execute executes a statement without returning row results
	Execute(query string, options *QueryOptions, values ...interface{}) error

	// ExecuteIterSimple executes a statement and returns iterator to the result set
	ExecuteIter(query string, options *QueryOptions, values ...interface{}) (ResultSet, error)

	// ChangeSchema executes a schema change query and waits for schema agreement
	ChangeSchema(query string, options *QueryOptions) error

	//TODO: Extract metadata methods from interface into another interface
	KeyspaceMetadata(keyspaceName string) (*gocql.KeyspaceMetadata, error)
}

type SessionMock

type SessionMock struct {
	mock.Mock
}

func NewSessionMock

func NewSessionMock() *SessionMock

func (*SessionMock) AddKeyspace

func (o *SessionMock) AddKeyspace(keyspace *gocql.KeyspaceMetadata) *mock.Call

func (*SessionMock) AddViews

func (o *SessionMock) AddViews(views []string) *mock.Call

func (*SessionMock) ChangeSchema

func (o *SessionMock) ChangeSchema(query string, options *QueryOptions) error

func (*SessionMock) Default

func (o *SessionMock) Default() *SessionMock

func (*SessionMock) Execute

func (o *SessionMock) Execute(query string, options *QueryOptions, values ...interface{}) error

func (*SessionMock) ExecuteIter

func (o *SessionMock) ExecuteIter(query string, options *QueryOptions, values ...interface{}) (ResultSet, error)

func (*SessionMock) KeyspaceMetadata

func (o *SessionMock) KeyspaceMetadata(keyspaceName string) (*gocql.KeyspaceMetadata, error)

func (*SessionMock) SetSchemaVersion

func (o *SessionMock) SetSchemaVersion(version string) *mock.Call

type SslOptions

type SslOptions struct {
	CaPath           string
	CertPath         string
	KeyPath          string
	HostVerification bool
}

type UpdateInfo

type UpdateInfo struct {
	Keyspace    string
	Table       *gocql.TableMetadata
	Columns     []string
	QueryParams []interface{}
	IfCondition []types.ConditionItem
	IfExists    bool
	TTL         int
}

Jump to

Keyboard shortcuts

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