コード例 #1
0
ファイル: channel_repository.go プロジェクト: gebv/hey
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
}
コード例 #2
0
ファイル: thread_repository.go プロジェクト: gebv/hey
// FindThreadByName find a thread by name
func (r *ThreadRepository) FindThreadByName(
	clientID,
	channelID uuid.UUID,
	name string,
) (hey.Thread, error) {
	thread := thread{}

	err := r.db.QueryRow(`
			SELECT 
				thread_id,
				client_id, 
				channel_id,
				owners,
				related_event_id,
				parent_thread_id
			FROM threads
			WHERE client_id = $1 AND channel_id = $2 AND ext_id = $3
		`, clientID, channelID, utils.HashText(name)).Scan(
		&thread.threadID,
		&thread.clientID,
		&thread.channelID,
		&thread.owners,
		&thread.relatedEventID,
		&thread.parentThreadID,
	)
	return &thread, err
}
コード例 #3
0
ファイル: channel_repository.go プロジェクト: gebv/hey
func (r *ChannelRepository) FindChannelByName(
	clientID uuid.UUID,
	channelName string,
) (hey.Channel, error) {
	channel := channel{}
	sql := `SELECT 
			channel_id,
			client_id,
			owners,
			root_thread_id,
			created_at,
			updated_at
		FROM channels
		WHERE client_id = $1 AND ext_id = $2`

	err := r.db.QueryRow(
		sql,
		clientID,
		utils.HashText(channelName),
	).Scan(
		&channel.channelID,
		&channel.clientID,
		&channel.owners,
		&channel.rootThreadID,
		&channel.createdAt,
		&channel.updatedAt,
	)

	return channel, err
}
コード例 #4
0
ファイル: thread_repository.go プロジェクト: gebv/hey
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
}