postgres

package
v0.0.0-...-8fb3740 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2016 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// PerPageMax max count items of page search
	PerPageMax = 100

	// PerPageDefault default count items of page search
	PerPageDefault = 25

	// TimeoutDefault default timeout of simple procedure
	TimeoutDefault time.Duration = 50

	// FindTimeoutDefault default timeout of search procedure
	FindTimeoutDefault = TimeoutDefault * 5

	DefaultPort     uint16 = 5432
	DefaultMaxConns int    = 10
)
View Source
var (
	ErrWantTx = errors.New("is only supported in transaction")
)
View Source
var SchemaBase = []string{
	`CREATE TABLE IF NOT EXISTS channels (
        channel_id uuid PRIMARY KEY,
        client_id uuid,

        ext_id text,
        
        owners uuid[],

        root_thread_id uuid,

        created_at timestamp with time zone NOT NULL,
        updated_at timestamp with time zone DEFAULT now() NOT NULL,

        CONSTRAINT uniq_client_channels_idx UNIQUE (client_id, ext_id)
    )`,
	`CREATE INDEX IF NOT EXISTS uniq_client_channels_idx ON channels(client_id, ext_id) WHERE (ext_id IS NOT NULL)`,
	`CREATE TABLE IF NOT EXISTS threads (
        thread_id uuid PRIMARY KEY,
        client_id uuid,
        channel_id uuid,

        ext_id text,
        
        owners uuid[],

        related_event_id uuid, -- в случае root = nil, в других случая отражает event с которым связан "вверх" поток
	    parent_thread_id uuid, -- в случае root = nil

        created_at timestamp with time zone NOT NULL,
        updated_at timestamp with time zone DEFAULT now() NOT NULL,
        
        CONSTRAINT uniq_client_threads_ids_idx UNIQUE (client_id, thread_id) 
    )`,
	`CREATE INDEX IF NOT EXISTS uniq_client_channel_threads_ext_ids_idx ON threads(client_id, channel_id, ext_id) WHERE (ext_id IS NOT NULL)`,
	`CREATE TABLE IF NOT EXISTS events (
        event_id uuid PRIMARY KEY,
        client_id uuid,
        thread_id uuid,
        channel_id uuid,

        creator uuid,

        data bytea,

        parent_thread_id uuid,
        parent_event_id uuid,
        branch_thread_id uuid,

        created_at timestamp with time zone NOT NULL,
        updated_at timestamp with time zone DEFAULT now() NOT NULL,
        
        CONSTRAINT uniq_client_event_idx UNIQUE (client_id, event_id)
    )`,
	`CREATE TABLE IF NOT EXISTS threadline (
        client_id uuid,
        channel_id uuid,
        thread_id uuid,

        event_id uuid PRIMARY KEY,

        created_at timestamp with time zone NOT NULL
    )`,
	`CREATE INDEX IF NOT EXISTS threadline_created_index ON threadline(
        client_id asc, 
--        channel_id asc, 
        thread_id asc, 
        created_at DESC, 
        event_id ASC
        )`,
}

Functions

func ClientIDFromContext

func ClientIDFromContext(ctx context.Context) uuid.UUID

ClientIDFromContext returns client ID from context

func SetupSchema

func SetupSchema(pg *pg.ConnPool) error

Types

type ChannelRepository

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

func (*ChannelRepository) CreateChannel

func (r *ChannelRepository) CreateChannel(
	tx *pg.Tx,
	clientID,
	channelID,
	rootThreadID uuid.UUID,
	owners []uuid.UUID,
) error

CreateChannel create new channel waiting in the context of the client ID (key name 'ClientID')

func (*ChannelRepository) CreateChannelWithName

func (r *ChannelRepository) CreateChannelWithName(
	tx *pg.Tx,
	clientID,
	channelID uuid.UUID,
	channelName string,
	rootThreadID uuid.UUID,
	owners []uuid.UUID,
) error

func (*ChannelRepository) FindChannel

func (r *ChannelRepository) FindChannel(
	clientID,
	channelID uuid.UUID,
) (hey.Channel, error)

func (*ChannelRepository) FindChannelByName

func (r *ChannelRepository) FindChannelByName(
	clientID uuid.UUID,
	channelName string,
) (hey.Channel, error)

type EventRepository

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

func (*EventRepository) CreateEvent

func (r *EventRepository) CreateEvent(
	tx *pg.Tx,
	clientID,
	eventID,
	threadID,
	channelID,
	creatorID,
	parentThreadID,
	parentEventID,
	branchThreadID uuid.UUID,
	data []byte,
) error

CreateEvent create new event waiting in the context of the client ID, channel ID, linked parent event and thread IDs

func (*EventRepository) CreateThreadline

func (r *EventRepository) CreateThreadline(
	tx *pg.Tx,
	clientID,
	channelID,
	threadID,
	eventID uuid.UUID,
) error

func (*EventRepository) DeleteThreadline

func (r *EventRepository) DeleteThreadline(
	tx *pg.Tx,
	clientID,
	eventID uuid.UUID,
) error

func (*EventRepository) FindEvent

func (r *EventRepository) FindEvent(
	clientID,
	eventID uuid.UUID,
) (hey.Event, error)

FindEvent get one event by ID

func (*EventRepository) FindEvents

func (r *EventRepository) FindEvents(
	clientID,
	watcherID,
	threadID uuid.UUID,
	cursorStr string,
	perPage int,
) ([]hey.Event, string, error)

FindEvents find events if the cursor is empty - first page else next pages if not valid cursor - first page

func (*EventRepository) SetBranchThreadID

func (r *EventRepository) SetBranchThreadID(
	tx *pg.Tx,
	clientID,
	eventID,
	branchThreadID uuid.UUID,
) error

SetBranchThreadID updates the branch thread ID

func (*EventRepository) Threadline

func (r *EventRepository) Threadline(
	tx *pg.Tx,
	clientID,
	channelID,
	threadID,
	eventID uuid.UUID,
) error

type SearchResult

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

SearchResult search result

func (SearchResult) Cursor

func (s SearchResult) Cursor() string

func (SearchResult) Events

func (s SearchResult) Events() []hey.Event

func (SearchResult) HasNext

func (s SearchResult) HasNext() bool

type Service

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

Service service of threads and events

func NewService

func NewService(
	db *pg.ConnPool,
	logger *log.Logger,
) *Service

NewService new hey service

func (*Service) CreateChannel

func (s *Service) CreateChannel(
	ctx context.Context,
	userIDs []uuid.UUID,
) (uuid.UUID, uuid.UUID, error)

func (*Service) CreateChannelName

func (s *Service) CreateChannelName(
	ctx context.Context,
	name string,
	userIDs []uuid.UUID,
) (uuid.UUID, uuid.UUID, error)

func (*Service) CreateEvent

func (s *Service) CreateEvent(ctx context.Context,
	threadID uuid.UUID,
	creatorID uuid.UUID,
	data []byte,
) (eventID uuid.UUID, err error)

CreateEvent create a new event to an existing thread

func (*Service) CreateNewBranchEvent

func (s *Service) CreateNewBranchEvent(
	ctx context.Context,
	threadID uuid.UUID,
	relatedEventID uuid.UUID,
	owners []uuid.UUID,
	creatorID uuid.UUID,
	data []byte,
) (uuid.UUID, uuid.UUID, error)

CreateNewBranchEvent create a new event in branch if the event already has the branch - error

func (*Service) CreateNewBranchEventWithThreadName

func (s *Service) CreateNewBranchEventWithThreadName(
	ctx context.Context,
	threadName string,
	threadID uuid.UUID,
	relatedEventID uuid.UUID,
	owners []uuid.UUID,
	creatorID uuid.UUID,
	data []byte,
) (uuid.UUID, uuid.UUID, error)

func (*Service) CreateNodalEvent

func (s *Service) CreateNodalEvent(
	ctx context.Context,
	threadID uuid.UUID,
	owners []uuid.UUID,
	creatorID uuid.UUID,
) (uuid.UUID, uuid.UUID, error)

CreateNodalEvent create new nodal event waiting ChannelID from context

func (*Service) CreateNodalEventWithData

func (s *Service) CreateNodalEventWithData(
	ctx context.Context,
	threadID uuid.UUID,
	owners []uuid.UUID,
	creatorID uuid.UUID,
	data []byte,
) (uuid.UUID, uuid.UUID, error)

CreateNodalEventWithData create new nodal event waiting ChannelID from context

func (*Service) CreateNodalEventWithThreadName

func (s *Service) CreateNodalEventWithThreadName(
	ctx context.Context,
	threadName string,
	threadID uuid.UUID,
	owners []uuid.UUID,
	creatorID uuid.UUID,
) (uuid.UUID, uuid.UUID, error)

CreateNodalEvent create new nodal event waiting ChannelID from context

func (*Service) CreateNodalEventWithThreadNameWithData

func (s *Service) CreateNodalEventWithThreadNameWithData(
	ctx context.Context,
	threadName string,
	threadID uuid.UUID,
	owners []uuid.UUID,
	creatorID uuid.UUID,
	data []byte,
) (uuid.UUID, uuid.UUID, error)

CreateNodalEventWithThreadNameWithData create new nodal event waiting ChannelID from context

func (*Service) FindChannelByName

func (s *Service) FindChannelByName(
	ctx context.Context,
	name string,
) (hey.Channel, error)

func (*Service) FindEvents

func (s *Service) FindEvents(
	ctx context.Context,
	watcherID uuid.UUID,
	threadID uuid.UUID,
	cursorStr string,
	perPage int,
) (hey.SearchResult, error)

FindEvents find events waiting WatcherID (from a user view) from context

func (*Service) FindEventsByName

func (s *Service) FindEventsByName(
	ctx context.Context,
	watcherID uuid.UUID,
	name string,
	cursorStr string,
	perPage int,
) (hey.SearchResult, error)

FindEvents find events waiting WatcherID (from a user view) from context

func (*Service) FindThreadByName

func (s *Service) FindThreadByName(
	ctx context.Context,
	channelID uuid.UUID,
	name string,
) (hey.Thread, error)

type ThreadRepository

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

func (*ThreadRepository) CreateThread

func (r *ThreadRepository) CreateThread(
	tx *pg.Tx,
	clientID,
	threadID,
	channelID,
	relatedEventID,
	parentThreadID uuid.UUID,
	owners []uuid.UUID,
) error

CreateThread create new thread waiting in the context of the client ID, linked event and thread IDs

func (*ThreadRepository) CreateThreadWithName

func (r *ThreadRepository) CreateThreadWithName(
	tx *pg.Tx,
	clientID,
	threadID uuid.UUID,
	threadName string,
	channelID,
	relatedEventID,
	parentThreadID uuid.UUID,
	owners []uuid.UUID,
) error

func (*ThreadRepository) FindThread

func (r *ThreadRepository) FindThread(
	clientID,
	threadID uuid.UUID,
) (hey.Thread, error)

FindThread returns thread

func (*ThreadRepository) FindThreadByName

func (r *ThreadRepository) FindThreadByName(
	clientID,
	channelID uuid.UUID,
	name string,
) (hey.Thread, error)

FindThreadByName find a thread by name

Jump to

Keyboard shortcuts

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