db

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetInMemSqliteDialector

func GetInMemSqliteDialector(dbName string) gorm.Dialector

GetInMemSqliteDialector define a in-memory Sqlite GORM dialector

@param dbName string - in-memory Sqlite DB name
@return GORM sqlite dialector

func GetPostgresDialector

func GetPostgresDialector(config common.PostgresConfig, password string) (gorm.Dialector, error)

GetPostgresDialector define Postgres driver dialector

@param config common.PostgresConfig - connection config
@param password string - user password
@returns GORM Postgres dialector

func GetSqliteDialector

func GetSqliteDialector(dbFile string) gorm.Dialector

GetSqliteDialector define Sqlite GORM dialector

@param dbFile string - Sqlite DB file
@return GORM sqlite dialector

Types

type ConnectionManager

type ConnectionManager interface {
	/*
		NewTransaction start and get handle to a new transaction

			@returns new transaction
	*/
	NewTransaction() *gorm.DB

	/*
		Commit Commit all changes within a transaction

			@param session *gorm.DB - the transaction session
	*/
	Commit(session *gorm.DB)

	/*
		Rollback revert all changes within a transaction

			@param session *gorm.DB - the transaction session
	*/
	Rollback(session *gorm.DB)

	/*
		NewPersistanceManager define a new DB access manager

			@returns new manager
	*/
	NewPersistanceManager() PersistenceManager
}

ConnectionManager manages connections and transactions with a DB

func NewSQLConnection

func NewSQLConnection(
	dbDialector gorm.Dialector, logLevel logger.LogLevel, noTransactions bool,
) (ConnectionManager, error)

NewSQLConnection define a new DB connection and transactions manager

@param dbDialector gorm.Dialector - GORM SQL dialector
@param logLevel logger.LogLevel - SQL log level
@param noTransactions bool - optionally, do not use transactions.
@returns new manager

type PersistenceManager

type PersistenceManager interface {
	/*
		Ready check whether the DB connection is working

			@param ctxt context.Context - execution context
	*/
	Ready(ctxt context.Context) error

	/*
		Close commit or rollback SQL queries within associated with this instance
	*/
	Close()

	/*
		Error error which occurred during the transaction

			@returns the error
	*/
	Error() error

	/*
		MarkExternalError record an external error with the manager to indicate failure that
		is unrelated to SQL operations but required SQL transaction rollback.

		This would force a transaction rollback when `Close` is called

			@param err error - the external error
	*/
	MarkExternalError(err error)

	/*
		DefineVideoSource create new video source

			@param ctxt context.Context - execution context
			@param name string - source name
			@param segmentLen int - target segment length in secs
			@param playlistURI *string - video source playlist URI
			@param description *string - optionally, source description
			@returns new source entry ID
	*/
	DefineVideoSource(
		ctxt context.Context, name string, segmentLen int, playlistURI, description *string,
	) (string, error)

	/*
		RecordKnownVideoSource create record for a known video source

			@param ctxt context.Context - execution context
			@param id string - source entry ID
			@param name string - source name
			@param segmentLen int - target segment length in secs
			@param playlistURI *string - video source playlist URI
			@param description *string - optionally, source description
			@param streaming int - whether the video source is currently streaming
	*/
	RecordKnownVideoSource(
		ctxt context.Context,
		id, name string,
		segmentLen int,
		playlistURI, description *string,
		streaming int,
	) error

	/*
		GetVideoSource retrieve a video source

			@param ctxt context.Context - execution context
			@param id string - source entry ID
			@returns video source entry
	*/
	GetVideoSource(ctxt context.Context, id string) (common.VideoSource, error)

	/*
		GetVideoSourceByName retrieve a video source by name

			@param ctxt context.Context - execution context
			@param name string - source name
			@returns video source entry
	*/
	GetVideoSourceByName(ctxt context.Context, name string) (common.VideoSource, error)

	/*
		ListVideoSources list all video sources

			@param ctxt context.Context - execution context
			@returns all video source entries
	*/
	ListVideoSources(ctxt context.Context) ([]common.VideoSource, error)

	/*
		UpdateVideoSource update properties of a video source.

		Only the following can be updated:
		  * Name
		  * Description
		  * Playlist URI

			@param ctxt context.Context - execution context
			@param newSetting common.VideoSource - new properties
	*/
	UpdateVideoSource(ctxt context.Context, newSetting common.VideoSource) error

	/*
		ChangeVideoSourceStreamState change the streaming state for a video source

			@param ctxt context.Context - execution context
			@param id string - source ID
			@param streaming int - new streaming state
	*/
	ChangeVideoSourceStreamState(ctxt context.Context, id string, streaming int) error

	/*
		UpdateVideoSourceStats update video source status fields

			@param ctxt context.Context - execution context
			@param id string - source ID
			@param reqRespTargetID string - the request-response target ID for reaching video source
			    over request-response network.
			@param sourceLocalTime time.Time - video source local time
	*/
	UpdateVideoSourceStats(
		ctxt context.Context, id string, reqRespTargetID string, sourceLocalTime time.Time,
	) error

	/*
		DeleteVideoSource delete a video source

			@param ctxt context.Context - execution context
			@param id string - source entry ID
	*/
	DeleteVideoSource(ctxt context.Context, id string) error

	/*
		RegisterLiveStreamSegment record a new segment with a source

			@param ctxt context.Context - execution context
			@param sourceID string - video source ID
			@param segment hls.Segment - video segment parameters
			@returns new segment entry ID
	*/
	RegisterLiveStreamSegment(
		ctxt context.Context, sourceID string, segment hls.Segment,
	) (string, error)

	/*
		BulkRegisterLiveStreamSegments register multiple segment in bulk

			@param ctxt context.Context - execution context
			@param sourceID string - video source ID
			@param segments []hls.Segment - set of video segments to insert
			@returns new segment entry IDs
	*/
	BulkRegisterLiveStreamSegments(
		ctxt context.Context, sourceID string, segments []hls.Segment,
	) (map[string]string, error)

	/*
		ListAllLiveStreamSegments fetch all video segments

			@param ctxt context.Context - execution context
			@param sourceID string - video source ID
			@returns list of segments
	*/
	ListAllLiveStreamSegments(ctxt context.Context, sourceID string) ([]common.VideoSegment, error)

	/*
		GetLiveStreamSegment get a video segment

			@param ctxt context.Context - execution context
			@param id string - video segment ID
			@returns segment
	*/
	GetLiveStreamSegment(ctxt context.Context, id string) (common.VideoSegment, error)

	/*
		GetLiveStreamSegmentByName get a video segment by name

			@param ctxt context.Context - execution context
			@param name string - video segment name
			@returns segment
	*/
	GetLiveStreamSegmentByName(ctxt context.Context, name string) (common.VideoSegment, error)

	/*
		ListAllLiveStreamSegmentsAfterTime fetch all video segments which have a stop timestamp
		after a timestamp

			@param ctxt context.Context - execution context
			@param sourceID string - video source ID
			@param timestamp time.Time - timestamp to check against
			@returns list of segments
	*/
	ListAllLiveStreamSegmentsAfterTime(
		ctxt context.Context, sourceID string, timestamp time.Time,
	) ([]common.VideoSegment, error)

	/*
		GetLatestLiveStreamSegments get the latest N video segments

			@param ctxt context.Context - execution context
			@param sourceID string - video source ID
			@param count int - number of segments to get
			@returns list of segments
	*/
	GetLatestLiveStreamSegments(
		ctxt context.Context, sourceID string, count int,
	) ([]common.VideoSegment, error)

	/*
		MarkLiveStreamSegmentsUploaded mark a set of live segment as uploaded

			@param ctxt context.Context - execution context
			@param ids []string - segment IDs
	*/
	MarkLiveStreamSegmentsUploaded(ctxt context.Context, ids []string) error

	/*
		DeleteLiveStreamSegment delete a segment

			@param ctxt context.Context - execution context
			@param id string - video segment ID
	*/
	DeleteLiveStreamSegment(ctxt context.Context, id string) error

	/*
		BulkDeleteLiveStreamSegment delete a group of segments

			@param ctxt context.Context - execution context
			@param ids []string - video segment IDs
	*/
	BulkDeleteLiveStreamSegment(ctxt context.Context, ids []string) error

	/*
		PurgeOldSegments delete segments older than a specific point in time

			@param ctxt context.Context - execution context
			@param timeLimit time.Time - video segment older than this point will be purged
	*/
	DeleteOldLiveStreamSegments(
		ctxt context.Context, timeLimit time.Time,
	) error

	/*
		DefineRecordingSession create new video recording session

			@param ctxt context.Context - execution context
			@param sourceID string - the video source ID
			@param alias *string - an optional alias name for the recording session
			@param description *string - an optional description of the recording session
			@param startTime time.Time - when the recording session started
			@returns new recording session ID
	*/
	DefineRecordingSession(
		ctxt context.Context, sourceID string, alias, description *string, startTime time.Time,
	) (string, error)

	/*
		RecordKnownRecordingSession create record for an existing video recording session

			@param ctxt context.Context - execution context
			@param entry common.Recording - video recording session entry
	*/
	RecordKnownRecordingSession(ctxt context.Context, entry common.Recording) error

	/*
		GetRecordingSession retrieve a video recording session

			@param ctxt context.Context - execution context
			@param id string - session entry ID
			@returns video recording entry
	*/
	GetRecordingSession(ctxt context.Context, id string) (common.Recording, error)

	/*
		GetRecordingSessionByAlias retrieve a video recording session by alias

			@param ctxt context.Context - execution context
			@param alias string - session entry alias
			@returns video recording entry
	*/
	GetRecordingSessionByAlias(ctxt context.Context, alias string) (common.Recording, error)

	/*
		ListRecordingSessions list all video recording sessions

			@param ctxt context.Context - execution context
			@returns all recording sessions
	*/
	ListRecordingSessions(ctxt context.Context) ([]common.Recording, error)

	/*
		ListRecordingSessionsOfSource list all video recording sessions of a video source

			@param ctxt context.Context - execution context
			@param sourceID string - the video source ID
			@param active bool - if 1, select only the active recording sessions; else return all.
			@returns all recording sessions of a video source
	*/
	ListRecordingSessionsOfSource(
		ctxt context.Context, sourceID string, active bool,
	) ([]common.Recording, error)

	/*
		MarkEndOfRecordingSession mark a video recording session as complete.

			@param ctxt context.Context - execution context
			@param id string - session entry ID
			@param endTime time.Time - when the recording session ended
	*/
	MarkEndOfRecordingSession(ctxt context.Context, id string, endTime time.Time) error

	/*
		UpdateRecordingSession update properties of a video recording session.

		Only the following can be updated:
		  * Alias
		  * Description

			@param ctxt context.Context - execution context
			@param newSetting common.Recording - new properties
	*/
	UpdateRecordingSession(ctxt context.Context, newSetting common.Recording) error

	/*
		DeleteRecordingSession delete a video recording session

			@param ctxt context.Context - execution context
			@param id string - session entry ID
	*/
	DeleteRecordingSession(ctxt context.Context, id string) error

	/*
		RegisterRecordingSegments record a set of new segments with a set of video recording sessions

			@param ctxt context.Context - execution context
			@param recordingIDs []string - video recording session IDs
			@param segments []common.VideoSegment - video segments
	*/
	RegisterRecordingSegments(
		ctxt context.Context, recordingIDs []string, segments []common.VideoSegment,
	) error

	/*
		GetRecordingSegments get a video segment of a video recording session

			@param ctxt context.Context - execution context
			@param id string - segment ID
			@returns the video segment
	*/
	GetRecordingSegment(ctxt context.Context, id string) (common.VideoSegment, error)

	/*
		GetRecordingSegmentByName get a video segment of a video recording session by name

			@param ctxt context.Context - execution context
			@param name string - video segment name
			@returns the video segment
	*/
	GetRecordingSegmentByName(ctxt context.Context, name string) (common.VideoSegment, error)

	/*
		ListAllRecordingSegments fetch all video segments belonging to recordings

			@param ctxt context.Context - execution context
			@returns set of video segments
	*/
	ListAllRecordingSegments(ctxt context.Context) ([]common.VideoSegment, error)

	/*
		ListAllSegmentsOfRecording fetch all video segments belonging to one recording session

			@param ctxt context.Context - execution context
			@param recordingID string - video recording session ID
			@returns set of video segments
	*/
	ListAllSegmentsOfRecording(
		ctxt context.Context, recordingID string,
	) ([]common.VideoSegment, error)

	/*
		DeleteUnassociatedRecordingSegments delete recording segments not attached to any
		video recording sessions

			@param ctxt context.Context - execution context
			@returns set of segments deleted
	*/
	DeleteUnassociatedRecordingSegments(ctxt context.Context) ([]common.VideoSegment, error)
}

PersistenceManager database access layer

Jump to

Keyboard shortcuts

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