Ejemplo n.º 1
0
func (r *ChannelRepository) CreateChannelWithName(
	tx *pg.Tx,
	clientID,
	channelID uuid.UUID,
	channelName string,
	rootThreadID uuid.UUID,
	owners []uuid.UUID,
) error {
	if tx == nil {
		return ErrWantTx
	}
	_, err := tx.Exec(`INSERT INTO channels (
            channel_id,
			ext_id,
            client_id,
            owners,
            root_thread_id,
            created_at,
            updated_at
        ) VALUES ($1, $2, $3, $4, $5, $6, $7)`,
		channelID,
		utils.HashText(channelName),
		clientID,
		utils.UUIDSFrom(owners),
		rootThreadID,
		time.Now(),
		time.Now(),
	)
	return err
}
Ejemplo n.º 2
0
func (r *EventRepository) DeleteThreadline(
	tx *pg.Tx,
	clientID,
	eventID uuid.UUID,
) error {
	_, err := tx.Exec(`DELETE FROM threadline WHERE 
			client_id = $1 AND 
			event_id = $2`,
		clientID,
		eventID,
	)

	return err
}
Ejemplo n.º 3
0
// CreateEvent create new event
// waiting in the context of the client ID, channel ID, linked parent
// event and thread IDs
func (r *EventRepository) CreateEvent(
	tx *pg.Tx,
	clientID,
	eventID,
	threadID,
	channelID,
	creatorID,
	parentThreadID,
	parentEventID,
	branchThreadID uuid.UUID,
	data []byte,
) error {
	_, err := tx.Exec(`INSERT INTO events (
            event_id,
            client_id,
            thread_id,
            channel_id,

            creator,

            data,

            parent_thread_id,
            parent_event_id,
            branch_thread_id,

            created_at,
            updated_at
        ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)`,
		eventID,
		clientID,
		threadID,
		channelID,
		creatorID,
		data, // data
		parentThreadID,
		parentEventID,
		branchThreadID, // branch thread id
		time.Now(),
		time.Now(),
	)
	return err
}
Ejemplo n.º 4
0
// SetBranchThreadID updates the branch thread ID
func (r *EventRepository) SetBranchThreadID(
	tx *pg.Tx,
	clientID,
	eventID,
	branchThreadID uuid.UUID,
) error {
	_, err := tx.Exec(`UPDATE events SET
			branch_thread_id = $1,
			updated_at = $2
			WHERE 
				client_id = $3 AND 
				event_id = $4 AND
				branch_thread_id = $5`,
		branchThreadID,
		time.Now(),
		clientID,
		eventID,
		uuid.Nil,
	)
	return err
}
Ejemplo n.º 5
0
func (r *EventRepository) Threadline(
	tx *pg.Tx,
	clientID,
	channelID,
	threadID,
	eventID uuid.UUID,
) error {
	_, err := tx.Exec(`INSERT INTO threadline (
			client_id,
			channel_id,
			thread_id,
			event_id,
			created_at
		) VALUES ($1, $2, $3, $4, $5)`,
		clientID,
		channelID,
		threadID,
		eventID,
		time.Now(),
	)
	return err
}
Ejemplo n.º 6
0
func (r *ThreadRepository) CreateThreadWithName(
	tx *pg.Tx,
	clientID,
	threadID uuid.UUID,
	threadName string,
	channelID,
	relatedEventID,
	parentThreadID uuid.UUID,
	owners []uuid.UUID,
) error {
	_, err := tx.Exec(`INSERT INTO threads (
            thread_id,
            client_id,
            channel_id,

			ext_id,

            owners,

            related_event_id,
            parent_thread_id,

            created_at,
            updated_at
        ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)`,
		threadID,
		clientID,
		channelID,
		utils.HashText(threadName),
		(&utils.UUIDS{}).FromArray(owners),
		relatedEventID,
		parentThreadID,
		time.Now(),
		time.Now(),
	)

	return err
}