db

package module
v0.0.0-...-845d9a5 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UnaryClientInterceptor

func UnaryClientInterceptor(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error

func UsersToProtoUsers

func UsersToProtoUsers(users []User) *pb.Users

UsersToProtoUsers transforms an array of User into an array of pb.Users which are auto-generated from protobuf.

Types

type DatabaseManager

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

DatabaseManager contains the connection pool to Vitess MySQL cluster. DatabaseManager's methods enable using the models with the rest of the cluster properly.

func NewDatabaseManager

func NewDatabaseManager() (dbm *DatabaseManager, err error)

NewDatabaseManager will create a new connection pool to Vitess MySQL cluster using the `users` keyspace.

TODO: add some configuration in the call of this function

func (*DatabaseManager) GetUserByID

func (dbm *DatabaseManager) GetUserByID(ctx context.Context, vtspanctx string, ID uint64) (user User, err error)

GetUserByID will returns a single User corresponding to the given ID.

func (*DatabaseManager) GetUsersOfRegion

func (dbm *DatabaseManager) GetUsersOfRegion(ctx context.Context, vtspanctx, region string) (users []User, err error)

GetUsersOfRegion fetches all the users matching the given region filter. It returns an array of Users, and an error if there is any. No other filter than region is being used thus, the function might be highly computational intensive depending on the data stored in Vitess.

func (*DatabaseManager) InsertUser

func (dbm *DatabaseManager) InsertUser(user User) (newID int, err error)

InsertUser inserts the given User into Vitess MySQL cluster. The new auto-generated ID will be returned, in addition to an error if any.

type MetaDataWriter

type MetaDataWriter struct {
	metadata.MD
}

MetaDataWriter interfaces opentracing.TextMap and is being used to propagate traces to the database cluster.

func (MetaDataWriter) ForeachKey

func (mdw MetaDataWriter) ForeachKey(handler func(key, val string) error) error

ForeachKey implements the Foreach function of opentracing.TextMap interface.

func (MetaDataWriter) Set

func (mdw MetaDataWriter) Set(key, val string)

Set implements the Set function of opentracing.TextMap interface.

type User

type User struct {
	ID              int64  `json:"id"`
	Timestamp       int64  `json:"timestamp"`
	UID             string `json:"uid"`
	Name            string `json:"name"`
	Gender          string `json:"gender"`
	Email           string `json:"email"`
	Phone           string `json:"phone"`
	Dept            string `json:"dept"`
	Grade           string `json:"grade"`
	Language        string `json:"language"`
	Region          string `json:"region"`
	Role            string `json:"role"`
	PreferTags      string `json:"prefer_tags"`
	ObtainedCredits string `json:"obtained_credits"`
}

User model maps to the user table of Vitess MySQL cluster. Implements encoding.BinaryMarshaler and encoding.BinaryUnmarshaler.

func ProtoUserToUser

func ProtoUserToUser(pbuser *pb.User) (user User)

ProtoUserToUser transforms an auto-generated pb.User from protobuf into the package implementation of User.

func (*User) MarshalBinary

func (u *User) MarshalBinary() (data []byte, err error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*User) ProtoUser

func (u *User) ProtoUser() *pb.User

ProtoUser transforms an User into a the auto-generated pb.User structure from protobuf.

func (*User) UnmarshalBinary

func (u *User) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

type UserArray

type UserArray []User

UserArray represents an array of User. Implements encoding.BinaryMarshaler and encoding.BinaryUnmarshaler.

func (*UserArray) MarshalBinary

func (ua *UserArray) MarshalBinary() (data []byte, err error)

MarshalBinary implements the encoding.BinaryMarshaler interface.

func (*UserArray) UnmarshalBinary

func (ua *UserArray) UnmarshalBinary(data []byte) error

UnmarshalBinary implements the encoding.BinaryUnmarshaler interface.

Jump to

Keyboard shortcuts

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