database

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2025 License: AGPL-3.0, AGPL-3.0-or-later Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AuthRepoName    = "/AUTH"
	PassSubName     = "PASS" // TODO pass restore functionality
	DefaultOwnerKey = "OWNER"
)
View Source
const (
	ChatNamespace     = "/CHATS"
	MessageNamespace  = "/MESSAGES"
	NonceSubNamespace = "NONCE"
)
View Source
const (
	LikeRepoName      = "/LIKE"
	IncrSubNamespace  = "INCR"
	LikerSubNamespace = "LIKER"
)
View Source
const (
	MediaRepoName     = "/MEDIA"
	ImageSubNamespace = "IMAGES"
	VideoSubNamespace = "VIDEOS"
)
View Source
const (
	NodesNamespace        = "/NODES"
	ProvidersSubNamespace = "PROVIDERS"
	BlocklistSubNamespace = "BLOCKLIST"
	SelfHashSubNamespace  = "SELFHASH"
	InfoSubNamespace      = "INFO"
)

slash is required because of: invalid datastore key: NODES:/peers/keys/AASAQAISEAXNRKHMX2O3AA26JM7NGIWUPOGIITJ2UHHXGX4OWIEKPNAW6YCSK/priv

View Source
const (
	ForeverBlockDuration time.Duration = 0
	MaxBlockDuration                   = 90 * 24 * time.Hour
)
View Source
const (
	TweetsNamespace = "/TWEETS"

	DefaultWarpnetTweetNetwork = "warpnet"
)
View Source
const (
	UsersRepoName = "/USERS"

	DefaultWarpnetUserNetwork = "warpnet"
)
View Source
const (
	FollowRepoName = "/FOLLOWINGS"
)
View Source
const (
	RepliesNamespace = "/REPLY"
)
View Source
const TimelineRepoName = "/TIMELINE"

Variables

View Source
var (
	ErrChatNotFound    = local.DBError("chat not found")
	ErrMessageNotFound = local.DBError("message not found")
)
View Source
var (
	ErrMediaNotFound    = local.DBError("media not found")
	ErrMediaRepoNotInit = local.DBError("media repo is not initialized")
)
View Source
var (
	ErrUserNotFound      = local.DBError("user not found")
	ErrUserAlreadyExists = local.DBError("user already exists")
)
View Source
var ErrAlreadyFollowed = local.DBError("already followed")
View Source
var ErrLikesNotFound = local.DBError("like not found")
View Source
var ErrNilAuthRepo = local.DBError("auth repo is nil")
View Source
var (
	ErrNilNodeRepo = local.DBError("node repo is nil")
)
View Source
var ErrNotInRecords = local.DBError("self hash is not in the consensus records")
View Source
var ErrReplyNotFound = local.DBError("reply not found")
View Source
var ErrTweetNotFound = local.DBError("tweet not found")

Functions

This section is empty.

Types

type AuthRepo

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

func NewAuthRepo

func NewAuthRepo(db AuthStorer) *AuthRepo

func (*AuthRepo) Authenticate

func (repo *AuthRepo) Authenticate(username, password string) (err error)

func (*AuthRepo) GetOwner

func (repo *AuthRepo) GetOwner() domain.Owner

func (*AuthRepo) PrivateKey

func (repo *AuthRepo) PrivateKey() ed25519.PrivateKey

func (*AuthRepo) SessionToken

func (repo *AuthRepo) SessionToken() string

func (*AuthRepo) SetOwner

func (repo *AuthRepo) SetOwner(o domain.Owner) (_ domain.Owner, err error)

type AuthStorer

type AuthStorer interface {
	Run(username, password string) (err error)
	Set(key local.DatabaseKey, value []byte) error
	Get(key local.DatabaseKey) ([]byte, error)
	NewTxn() (local.WarpTransactioner, error)
}

type Base64Image

type Base64Image string

type BlocklistedItem added in v0.3.9

type BlocklistedItem struct {
	PeerID   warpnet.WarpPeerID
	Duration *time.Duration
}

type ChatRepo

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

func NewChatRepo

func NewChatRepo(db ChatStorer) *ChatRepo

func (*ChatRepo) CreateChat

func (repo *ChatRepo) CreateChat(chatId *string, ownerId, otherUserId string) (chat domain.Chat, err error)

func (*ChatRepo) CreateMessage

func (repo *ChatRepo) CreateMessage(msg domain.ChatMessage) (domain.ChatMessage, error)

func (*ChatRepo) DeleteChat

func (repo *ChatRepo) DeleteChat(chatId string) error

func (*ChatRepo) DeleteMessage

func (repo *ChatRepo) DeleteMessage(chatId, id string) error

func (*ChatRepo) GetChat

func (repo *ChatRepo) GetChat(chatId string) (chat domain.Chat, err error)

func (*ChatRepo) GetMessage

func (repo *ChatRepo) GetMessage(chatId, id string) (m domain.ChatMessage, err error)

func (*ChatRepo) GetUserChats

func (repo *ChatRepo) GetUserChats(userId string, limit *uint64, cursor *string) ([]domain.Chat, string, error)

func (*ChatRepo) ListMessages

func (repo *ChatRepo) ListMessages(chatId string, limit *uint64, cursor *string) ([]domain.ChatMessage, string, error)

type ChatStorer

type ChatStorer interface {
	NewTxn() (local.WarpTransactioner, error)
}

type FollowRepo

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

FollowRepo handles reader/writer relationships

func NewFollowRepo

func NewFollowRepo(db FollowerStorer) *FollowRepo

func (*FollowRepo) Follow

func (repo *FollowRepo) Follow(fromUserId, toUserId string, event domain.Following) error

func (*FollowRepo) GetFollowees

func (repo *FollowRepo) GetFollowees(userId string, limit *uint64, cursor *string) ([]domain.Following, string, error)

GetFollowees followee - one who is followed (has his/her posts monitored by another user)

func (*FollowRepo) GetFolloweesCount

func (repo *FollowRepo) GetFolloweesCount(userId string) (uint64, error)

func (*FollowRepo) GetFollowers

func (repo *FollowRepo) GetFollowers(userId string, limit *uint64, cursor *string) ([]domain.Following, string, error)

func (*FollowRepo) GetFollowersCount

func (repo *FollowRepo) GetFollowersCount(userId string) (uint64, error)

func (*FollowRepo) Unfollow

func (repo *FollowRepo) Unfollow(fromUserId, toUserId string) error

type FollowerStorer

type FollowerStorer interface {
	NewTxn() (local.WarpTransactioner, error)
	Set(key local.DatabaseKey, value []byte) error
	Get(key local.DatabaseKey) ([]byte, error)
	Delete(key local.DatabaseKey) error
}

type ImageKey

type ImageKey string

type LikeRepo

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

func NewLikeRepo

func NewLikeRepo(db LikeStorer) *LikeRepo

func (*LikeRepo) Like

func (repo *LikeRepo) Like(tweetId, userId string) (likesCount uint64, err error)

func (*LikeRepo) Likers

func (repo *LikeRepo) Likers(tweetId string, limit *uint64, cursor *string) (_ likedUserIDs, cur string, err error)

func (*LikeRepo) LikesCount

func (repo *LikeRepo) LikesCount(tweetId string) (likesNum uint64, err error)

func (*LikeRepo) Unlike

func (repo *LikeRepo) Unlike(tweetId, userId string) (likesCount uint64, err error)

type LikeStorer

type LikeStorer interface {
	Get(key local.DatabaseKey) ([]byte, error)
	NewTxn() (local.WarpTransactioner, error)
}

type MediaRepo

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

func NewMediaRepo

func NewMediaRepo(db MediaStorer) *MediaRepo

func (*MediaRepo) GetImage

func (repo *MediaRepo) GetImage(userId, key string) (Base64Image, error)

func (*MediaRepo) SetForeignImageWithTTL

func (repo *MediaRepo) SetForeignImageWithTTL(userId, key string, img Base64Image) error

func (*MediaRepo) SetImage

func (repo *MediaRepo) SetImage(userId string, img Base64Image) (_ ImageKey, err error)

type MediaStorer

type MediaStorer interface {
	Set(key local.DatabaseKey, value []byte) error
	Get(key local.DatabaseKey) ([]byte, error)
	SetWithTTL(key local.DatabaseKey, value []byte, ttl time.Duration) error
}

type NodeRepo

type NodeRepo struct {
	BootstrapSelfHashHex string
	// contains filtered or unexported fields
}

func NewNodeRepo

func NewNodeRepo(db NodeStorer, version *semver.Version) (*NodeRepo, error)

func (*NodeRepo) AddSelfHash added in v0.3.15

func (d *NodeRepo) AddSelfHash(selfHashHex, version string) error

func (*NodeRepo) Batch

func (d *NodeRepo) Batch(ctx context.Context) (ds.Batch, error)

Batch creates a new Batch object. This provides a way to do many writes, when there may be too many to fit into a single transaction.

func (*NodeRepo) BlocklistExponential added in v0.3.9

func (d *NodeRepo) BlocklistExponential(peerId warpnet.WarpPeerID) error

func (*NodeRepo) BlocklistRemove

func (d *NodeRepo) BlocklistRemove(peerId warpnet.WarpPeerID) (err error)

func (*NodeRepo) Close

func (d *NodeRepo) Close() (err error)

func (*NodeRepo) Delete

func (d *NodeRepo) Delete(ctx context.Context, key ds.Key) error

func (*NodeRepo) DiskUsage

func (d *NodeRepo) DiskUsage(ctx context.Context) (uint64, error)

DiskUsage implements the PersistentDatastore interface. It returns the sum of lsm and value log files sizes in bytes.

func (*NodeRepo) Get

func (d *NodeRepo) Get(ctx context.Context, key ds.Key) (value []byte, err error)

func (*NodeRepo) GetExpiration

func (d *NodeRepo) GetExpiration(ctx context.Context, key ds.Key) (t time.Time, err error)

func (*NodeRepo) GetSelfHashes added in v0.3.15

func (d *NodeRepo) GetSelfHashes() (map[string]struct{}, error)

func (*NodeRepo) GetSize

func (d *NodeRepo) GetSize(ctx context.Context, key ds.Key) (_ int, err error)

func (*NodeRepo) Has

func (d *NodeRepo) Has(ctx context.Context, key ds.Key) (_ bool, err error)

func (*NodeRepo) IsBlocklisted

func (d *NodeRepo) IsBlocklisted(peerId warpnet.WarpPeerID) (bool, error)

func (*NodeRepo) PruneOldSelfHashes added in v0.3.9

func (d *NodeRepo) PruneOldSelfHashes(currentVersion *semver.Version) error

func (*NodeRepo) Put

func (d *NodeRepo) Put(ctx context.Context, key ds.Key, value []byte) error

func (*NodeRepo) PutWithTTL

func (d *NodeRepo) PutWithTTL(ctx context.Context, key ds.Key, value []byte, ttl time.Duration) error

func (*NodeRepo) Query

func (d *NodeRepo) Query(ctx context.Context, q dsq.Query) (res dsq.Results, err error)

func (*NodeRepo) SetTTL

func (d *NodeRepo) SetTTL(ctx context.Context, key ds.Key, ttl time.Duration) error

func (*NodeRepo) Sync

func (d *NodeRepo) Sync(ctx context.Context, _ ds.Key) error

func (*NodeRepo) ValidateSelfHash added in v0.3.53

func (d *NodeRepo) ValidateSelfHash(ev event.ValidationEvent) error

type NodeStorer

type NodeStorer interface {
	NewTxn() (local.WarpTransactioner, error)
	Get(key local.DatabaseKey) ([]byte, error)
	GetExpiration(key local.DatabaseKey) (uint64, error)
	GetSize(key local.DatabaseKey) (int64, error)
	Sync() error
	IsClosed() bool
	InnerDB() *local.WarpDB
	SetWithTTL(key local.DatabaseKey, value []byte, ttl time.Duration) error
	Set(key local.DatabaseKey, value []byte) error
	Delete(key local.DatabaseKey) error
}

type ReplyRepo

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

func NewRepliesRepo

func NewRepliesRepo(db ReplyStorer) *ReplyRepo

func (*ReplyRepo) AddReply

func (repo *ReplyRepo) AddReply(reply domain.Tweet) (domain.Tweet, error)

func (*ReplyRepo) DeleteReply

func (repo *ReplyRepo) DeleteReply(rootID, parentID, replyID string) error

func (*ReplyRepo) GetRepliesTree

func (repo *ReplyRepo) GetRepliesTree(rootId, parentId string, limit *uint64, cursor *string) ([]domain.ReplyNode, string, error)

func (*ReplyRepo) GetReply

func (repo *ReplyRepo) GetReply(rootID string, replyId string) (tweet domain.Tweet, err error)

func (*ReplyRepo) RepliesCount

func (repo *ReplyRepo) RepliesCount(tweetId string) (likesNum uint64, err error)

type ReplyStorer

type ReplyStorer interface {
	Set(key local.DatabaseKey, value []byte) error
	Get(key local.DatabaseKey) ([]byte, error)
	Delete(key local.DatabaseKey) error
	NewTxn() (local.WarpTransactioner, error)
}

type TimelineRepo

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

func NewTimelineRepo

func NewTimelineRepo(db TimelineStorer) *TimelineRepo

func (*TimelineRepo) AddTweetToTimeline

func (repo *TimelineRepo) AddTweetToTimeline(userId string, tweet domain.Tweet) error

func (*TimelineRepo) DeleteTweetFromTimeline

func (repo *TimelineRepo) DeleteTweetFromTimeline(userID, tweetID string, createdAt time.Time) error

func (*TimelineRepo) GetTimeline

func (repo *TimelineRepo) GetTimeline(userId string, limit *uint64, cursor *string) ([]domain.Tweet, string, error)

GetTimeline retrieves a user's timeline sorted from newest to oldest

type TimelineStorer

type TimelineStorer interface {
	Set(key local.DatabaseKey, value []byte) error
	NewTxn() (local.WarpTransactioner, error)
	Delete(key local.DatabaseKey) error
}

type TweetRepo

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

func NewTweetRepo

func NewTweetRepo(db TweetsStorer) *TweetRepo

func (*TweetRepo) Create

func (repo *TweetRepo) Create(userId string, tweet domain.Tweet) (domain.Tweet, error)

Create adds a new tweet to the database

func (*TweetRepo) CreateWithTTL added in v0.3.61

func (repo *TweetRepo) CreateWithTTL(userId string, tweet domain.Tweet, duration time.Duration) (domain.Tweet, error)

func (*TweetRepo) Delete

func (repo *TweetRepo) Delete(userID, tweetID string) error

Delete removes a tweet by its ID

func (*TweetRepo) Get

func (repo *TweetRepo) Get(userID, tweetID string) (tweet domain.Tweet, err error)

Get retrieves a tweet by its ID

func (*TweetRepo) List

func (repo *TweetRepo) List(userId string, limit *uint64, cursor *string) ([]domain.Tweet, string, error)

func (*TweetRepo) NewRetweet

func (repo *TweetRepo) NewRetweet(tweet domain.Tweet) (_ domain.Tweet, err error)

func (*TweetRepo) Retweeters

func (repo *TweetRepo) Retweeters(tweetId string, limit *uint64, cursor *string) (_ retweetersIDs, cur string, err error)

func (*TweetRepo) RetweetsCount

func (repo *TweetRepo) RetweetsCount(tweetId string) (uint64, error)

func (*TweetRepo) TweetsCount

func (repo *TweetRepo) TweetsCount(userId string) (uint64, error)

func (*TweetRepo) UnRetweet

func (repo *TweetRepo) UnRetweet(retweetedByUserID, tweetId string) error

type TweetsStorer

type TweetsStorer interface {
	NewTxn() (local.WarpTransactioner, error)
	Set(key local.DatabaseKey, value []byte) error
	Get(key local.DatabaseKey) ([]byte, error)
	Delete(key local.DatabaseKey) error
}

type UserRepo

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

func NewUserRepo

func NewUserRepo(db UserStorer) *UserRepo

func (*UserRepo) Create

func (repo *UserRepo) Create(user domain.User) (domain.User, error)

Create adds a new user to the database

func (*UserRepo) CreateWithTTL added in v0.3.61

func (repo *UserRepo) CreateWithTTL(user domain.User, ttl time.Duration) (domain.User, error)

func (*UserRepo) Delete

func (repo *UserRepo) Delete(userId string) error

Delete removes a user by their ID

func (*UserRepo) Get

func (repo *UserRepo) Get(userId string) (user domain.User, err error)

Get retrieves a user by their ID

func (*UserRepo) GetBatch

func (repo *UserRepo) GetBatch(userIDs ...string) (users []domain.User, err error)

func (*UserRepo) GetByNodeID

func (repo *UserRepo) GetByNodeID(nodeID string) (user domain.User, err error)

func (*UserRepo) List

func (repo *UserRepo) List(limit *uint64, cursor *string) ([]domain.User, string, error)

func (*UserRepo) Update

func (repo *UserRepo) Update(userId string, newUser domain.User) (domain.User, error)

func (*UserRepo) ValidateUserID added in v0.3.75

func (repo *UserRepo) ValidateUserID(ev event.ValidationEvent) error

ValidateUser if already taken

func (*UserRepo) WhoToFollow added in v0.3.75

func (repo *UserRepo) WhoToFollow(limit *uint64, cursor *string) ([]domain.User, string, error)

type UserStorer

type UserStorer interface {
	NewTxn() (local.WarpTransactioner, error)
	Set(key local.DatabaseKey, value []byte) error
	Get(key local.DatabaseKey) ([]byte, error)
	Delete(key local.DatabaseKey) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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