cqldao

package
v0.0.0-...-176f8cf Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MAX_NUM_GUESTS            = 100 // Not used by now
	MAX_EVENTS_IN_RECENT_LIST = 100 // Not used by now

)
View Source
const (
	MAX_NUM_FRIENDS     = 1000
	AVG_GROUPS_PER_USER = 10
)
View Source
const (
	GRACE_PERIOD_MS = 15 * 1000 // 15s
)
View Source
const (
	MAX_EVENTS_IN_HISTORY_LIST = 15
)

Variables

View Source
var (
	ErrNoSession        = errors.New("no session to Cassandra available")
	ErrGracePeriod      = errors.New("grace period due to old and new conflict")
	ErrUnexpected       = errors.New("unexpected error")
	ErrInconsistency    = errors.New("db inconsistency detected")
	ErrIllegalArguments = errors.New("illegal arguments")
)
View Source
var (
	EMPTY_ARRAY_32B = [32]byte{}
)

Functions

func NewAccessTokenDAO

func NewAccessTokenDAO(session api.DbSession) api.AccessTokenDAO

func NewEventDAO

func NewEventDAO(session api.DbSession) api.EventDAO

func NewEventHistoryDAO

func NewEventHistoryDAO(session api.DbSession) api.EventHistoryDAO

func NewFriendDAO

func NewFriendDAO(session api.DbSession) api.FriendDAO

func NewFriendRequestDAO

func NewFriendRequestDAO(session api.DbSession) api.FriendRequestDAO

func NewLogDAO

func NewLogDAO(session api.DbSession) api.LogDAO

func NewSettingsDAO

func NewSettingsDAO(session api.DbSession) api.SettingsDAO

func NewThumbnailDAO

func NewThumbnailDAO(session api.DbSession) api.ThumbnailDAO

func NewTimeLineDAO

func NewTimeLineDAO(session api.DbSession) api.EventTimeLineDAO

func NewUserDAO

func NewUserDAO(session api.DbSession) api.UserDAO

Types

type AccessTokenDAO

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

func (*AccessTokenDAO) Insert

func (d *AccessTokenDAO) Insert(accessToken *api.AccessTokenDTO) error

func (*AccessTokenDAO) Load

func (d *AccessTokenDAO) Load(userId int64) (*api.AccessTokenDTO, error)

func (*AccessTokenDAO) Remove

func (d *AccessTokenDAO) Remove(userId int64) error

func (*AccessTokenDAO) SetLastUsed

func (d *AccessTokenDAO) SetLastUsed(user_id int64, time int64) error

type EventDAO

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

func (*EventDAO) DeleteAll

func (d *EventDAO) DeleteAll() error

func (*EventDAO) Insert

func (d *EventDAO) Insert(event *api.EventDTO) error

Insert event into database with timestamp the one of the event. Participant will have the same timestamp.

func (*EventDAO) InsertParticipant

func (d *EventDAO) InsertParticipant(p *api.ParticipantDTO) error

func (*EventDAO) LoadEventPicture

func (de *EventDAO) LoadEventPicture(event_id int64) (*api.PictureDTO, error)

func (*EventDAO) LoadEvents

func (d *EventDAO) LoadEvents(event_ids ...int64) ([]*api.EventDTO, error)

Read one or more events and their participants. Event info and participants are in the same partition

func (*EventDAO) LoadParticipant

func (d *EventDAO) LoadParticipant(participantID int64, eventID int64) (*api.ParticipantDTO, error)

func (*EventDAO) RangeAll

func (d *EventDAO) RangeAll(f func(*api.EventDTO) error) error

func (*EventDAO) RangeEvents

func (d *EventDAO) RangeEvents(f func(*api.EventDTO) error, event_ids ...int64) error

func (*EventDAO) Replace

func (d *EventDAO) Replace(oldEvent *api.EventDTO, newEvent *api.EventDTO) error

Replace modifies information of an existing event. This implementation only changes message, start_date, end_date, inbox_position and event state. Moreover, it doesn't modify information related to existing participants but only can add new ones where version isn't set. NOTE: This implementation takes into account the single use case where an event update contains new participants only.

func (*EventDAO) SetEventPicture

func (dao *EventDAO) SetEventPicture(event_id int64, picture *api.PictureDTO) error

type EventHistoryDAO

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

func (*EventHistoryDAO) DeleteAll

func (d *EventHistoryDAO) DeleteAll() error

func (*EventHistoryDAO) FindAllBackward

func (d *EventHistoryDAO) FindAllBackward(userID int64, fromDate time.Time) ([]int64, error)

func (*EventHistoryDAO) FindAllForward

func (d *EventHistoryDAO) FindAllForward(userID int64, fromDate time.Time) ([]int64, error)

func (*EventHistoryDAO) Insert

func (d *EventHistoryDAO) Insert(userID int64, entry *api.TimeLineEntryDTO) error

func (*EventHistoryDAO) InsertBatch

func (d *EventHistoryDAO) InsertBatch(entry *api.TimeLineEntryDTO, userIDs ...int64) error

type EventTimeLineDAO

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

Beginning of time line has the event with earliest end date

func (*EventTimeLineDAO) Delete

func (d *EventTimeLineDAO) Delete(item *api.TimeLineEntryDTO) error

func (*EventTimeLineDAO) DeleteAll

func (d *EventTimeLineDAO) DeleteAll() error

func (*EventTimeLineDAO) FindAllBackward

func (d *EventTimeLineDAO) FindAllBackward(date time.Time) ([]*api.TimeLineEntryDTO, error)

func (*EventTimeLineDAO) FindAllBetween

func (d *EventTimeLineDAO) FindAllBetween(fromDate time.Time, toDate time.Time) ([]*api.TimeLineEntryDTO, error)

func (*EventTimeLineDAO) FindAllForward

func (d *EventTimeLineDAO) FindAllForward(date time.Time) ([]*api.TimeLineEntryDTO, error)

func (*EventTimeLineDAO) Insert

func (d *EventTimeLineDAO) Insert(item *api.TimeLineEntryDTO) error

func (*EventTimeLineDAO) Replace

func (d *EventTimeLineDAO) Replace(oldItem *api.TimeLineEntryDTO, newItem *api.TimeLineEntryDTO) error

type FriendDAO

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

func (*FriendDAO) AddMembers

func (d *FriendDAO) AddMembers(user_id int64, group_id int32, friend_ids ...int64) error

Add one or more members into the same group

func (*FriendDAO) ContainsFriend

func (dao *FriendDAO) ContainsFriend(user_id int64, other_user_id int64) (bool, error)

func (*FriendDAO) DeleteGroup

func (dao *FriendDAO) DeleteGroup(user_id int64, group_id int32) error

func (*FriendDAO) DeleteMembers

func (d *FriendDAO) DeleteMembers(user_id int64, group_id int32, friend_ids ...int64) error

Delete one or more members from the same group

func (*FriendDAO) InsertGroup

func (dao *FriendDAO) InsertGroup(user_id int64, group *api.GroupDTO) error

Add a new group with members. If a group contains members, they must be all of the members in the group.

func (*FriendDAO) LoadFriends

func (d *FriendDAO) LoadFriends(user_id int64, group_id int32) ([]*api.FriendDTO, error)

func (*FriendDAO) LoadGroups

func (d *FriendDAO) LoadGroups(user_id int64) ([]*api.GroupDTO, error)

func (*FriendDAO) LoadGroupsWithMembers

func (dao *FriendDAO) LoadGroupsWithMembers(user_id int64) ([]*api.GroupDTO, error)

func (*FriendDAO) MakeFriends

func (dao *FriendDAO) MakeFriends(user1 *api.FriendDTO, user2 *api.FriendDTO) error

func (*FriendDAO) SetFriendPictureDigest

func (dao *FriendDAO) SetFriendPictureDigest(user_id int64, friend_id int64, digest []byte) error

func (*FriendDAO) SetGroupName

func (dao *FriendDAO) SetGroupName(user_id int64, group_id int32, name string) error

type FriendRequestDAO

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

func (*FriendRequestDAO) Delete

func (d *FriendRequestDAO) Delete(friendRequest *api.FriendRequestDTO) error

func (*FriendRequestDAO) Exist

func (d *FriendRequestDAO) Exist(fromUser int64, toUser int64) (bool, error)

Check if exists a friend request from user_id to friend_id. In other words, if user_id has already sent (or not) a friend request to friend_id.

func (*FriendRequestDAO) Insert

func (d *FriendRequestDAO) Insert(friendRequest *api.FriendRequestDTO) error

Insert a friend request into database. This request means that some user (friend_id) wants to be friend of user_id

func (*FriendRequestDAO) Load

func (d *FriendRequestDAO) Load(fromUser int64, toUser int64) (*api.FriendRequestDTO, error)

func (*FriendRequestDAO) LoadAll

func (d *FriendRequestDAO) LoadAll(user_id int64) ([]*api.FriendRequestDTO, error)

type GocqlSession

type GocqlSession struct {
	*gocql.Session
	// contains filtered or unexported fields
}

func NewSession

func NewSession(keyspace string, cqlVersion int, hosts ...string) *GocqlSession

func (*GocqlSession) Connect

func (self *GocqlSession) Connect() error

func (*GocqlSession) IsValid

func (self *GocqlSession) IsValid() bool

type LogDAO

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

func (*LogDAO) FindActiveSessions

func (d *LogDAO) FindActiveSessions(node int, forDay time.Time) ([]*api.ActiveSessionInfoDTO, error)

func (*LogDAO) LogActiveSession

func (d *LogDAO) LogActiveSession(node int, user_id int64, last_time int64) error

func (*LogDAO) LogRegisteredUser

func (d *LogDAO) LogRegisteredUser(user_id int64, created_date int64) error

type SettingsDAO

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

func (*SettingsDAO) Find

func (d *SettingsDAO) Find(key api.SettingOption) (string, error)

func (*SettingsDAO) Insert

func (d *SettingsDAO) Insert(key api.SettingOption, value string) error

type ThumbnailDAO

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

func (*ThumbnailDAO) Insert

func (dao *ThumbnailDAO) Insert(id int64, digest []byte, thumbnails map[int32][]byte) error

Insert thumbnails into database. A batch implementation was used before, however it reaches Cassandra's batch_size limit of 50 Kb (despite being inserted to the same partition key). So a one-by-one insert implementation is preferred. If one of the inserts fails, this implementation keeps the first error but continues inserting the remainder ones. All errors are logged.

func (*ThumbnailDAO) Load

func (dao *ThumbnailDAO) Load(id int64, dpi int32) ([]byte, error)

func (*ThumbnailDAO) Remove

func (dao *ThumbnailDAO) Remove(id int64) error

type UserDAO

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

func (*UserDAO) Delete

func (dao *UserDAO) Delete(user *api.UserDTO) error

User information is spread in three tables: user_account, user_email_credentials and user_facebook_credentials. So, in order to delete a user, it's needed an user_id, e-mail and, likely, a Facebook ID. For the sake of safety, a read is perform before delete in order to perform security checks between data provided as argument and data stored in database. If all of the security checks passed, then user is removed.

func (*UserDAO) DeleteAll

func (d *UserDAO) DeleteAll() error

func (*UserDAO) Insert

func (d *UserDAO) Insert(user *api.UserDTO) error

Insert a new user into Cassandra involving tables user_account, user_email_credentials and user_facebook_credentials. It takes account race conditions like two users trying to create the same account simultaneously. If email is already taken this operation fails. In the same way, if FB account is already linked to a valid user account (row exists in user_account and user_email_credential), then this operation fails. With this implementation, orphan fb rows are removed after a grace period time in order to enable retry logic in the client when, by some reason, registration failed at first attempt. This function does not remove user account, it only updates orphaned user_facebook_credentials rows that doesn't point to a valid user account. In order to work properly, a row in user_email_credentials must be inserted before GRACE_PERIOD_MS. Otherwise, another account could reclaim that FB for itself with another Insert call.

func (*UserDAO) InsertFacebookCredentials

func (d *UserDAO) InsertFacebookCredentials(userId int64, fbId string, fbToken string) (ok bool, err error)

Try to insert Facebook credentials. If it fails because of a collision, retrieve the row causing that collision, compare created_date with grace_period and check if that row belongs to a valid account. If grace_period seconds have elapsed since created_date and account isn't valid, then remove row causing conflict and retry. Otherwise, if account is valid, returns ErrFacebookAlreadyExists. If grace_period seconds haven't elapsed yet since created_date then return ErrGracePeriod .

func (*UserDAO) Int_CheckUserConsistency

func (d *UserDAO) Int_CheckUserConsistency(user *api.UserDTO) (bool, error)

func (*UserDAO) Int_LoadAllUserAccount

func (d *UserDAO) Int_LoadAllUserAccount() ([]*api.UserDTO, error)

TODO: Include Password and Salt in user_account table TODO: Make up some type of high level iterator in order to control scanning steps in model layer.

func (*UserDAO) Int_LoadEmailCredential

func (d *UserDAO) Int_LoadEmailCredential(email string) (*emailCredential, error)

func (*UserDAO) Int_LoadFacebookCredential

func (d *UserDAO) Int_LoadFacebookCredential(fbId string) (*fbCredential, error)

func (*UserDAO) Int_LoadUserAccount

func (d *UserDAO) Int_LoadUserAccount(userId int64) (*api.UserDTO, error)

func (*UserDAO) Load

func (d *UserDAO) Load(userId int64) (*api.UserDTO, error)

func (*UserDAO) LoadByEmail

func (d *UserDAO) LoadByEmail(email string) (*api.UserDTO, error)

func (*UserDAO) LoadByFB

func (d *UserDAO) LoadByFB(fbId string) (*api.UserDTO, error)

func (*UserDAO) LoadIIDToken

func (d *UserDAO) LoadIIDToken(userId int64) (*api.IIDTokenDTO, error)

func (*UserDAO) LoadProfilePicture

func (d *UserDAO) LoadProfilePicture(user_id int64) (*api.PictureDTO, error)

func (*UserDAO) SaveProfilePicture

func (d *UserDAO) SaveProfilePicture(user_id int64, picture *api.PictureDTO) error

func (*UserDAO) SetAuthToken

func (d *UserDAO) SetAuthToken(user_id int64, auth_token string) error

func (*UserDAO) SetFacebook

func (d *UserDAO) SetFacebook(userID int64, fbID string, fbToken string) error

SetFacebook sets facebook id and access token for the account user_id regardless fbId exists also as facebook credentials.

func (*UserDAO) SetFacebookCredential

func (d *UserDAO) SetFacebookCredential(userID int64, fbID string, fbToken string) error

UpdateFacebookCredential sets facebook id and access token for the account user_id and also set facebook as credential

func (*UserDAO) SetIIDToken

func (d *UserDAO) SetIIDToken(userID int64, iidToken *api.IIDTokenDTO) error

func (*UserDAO) SetLastConnection

func (d *UserDAO) SetLastConnection(user_id int64, time int64) error

func (*UserDAO) SetPassword

func (d *UserDAO) SetPassword(email string, newPassword [32]byte, newSalt [32]byte) (bool, error)

Jump to

Keyboard shortcuts

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