common

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: AGPL-3.0 Imports: 58 Imported by: 1

README

dbhub-common

Golang code in common between the various DBHub projects

Documentation

Index

Constants

View Source
const (
	TODAY      ActivityRange = "today"
	THIS_WEEK                = "week"
	THIS_MONTH               = "month"
	ALL_TIME                 = "all"
)
View Source
const (
	TREE     DBTreeEntryType = "tree"
	DATABASE                 = "db"
	LICENCE                  = "licence"
)
View Source
const (
	TEXT   DiscussionCommentType = "txt"
	CLOSE                        = "cls"
	REOPEN                       = "rop"
)
View Source
const (
	EVENT_NEW_DISCUSSION    EventType = 0 // These are not iota, as it would be seriously bad for these numbers to change
	EVENT_NEW_MERGE_REQUEST           = 1
	EVENT_NEW_COMMENT                 = 2
	EVENT_NEW_RELEASE                 = 3
)
View Source
const (
	OPEN                 MergeRequestState = 0 // These are not iota, as it would be seriously bad for these numbers to change
	CLOSED_WITH_MERGE                      = 1
	CLOSED_WITHOUT_MERGE                   = 2
)
View Source
const DefaultNumDisplayRows = 25

DefaultNumDisplayRows is the number of rows to display by default on the database page

View Source
const MaxDatabaseSize = 512

MaxDatabaseSize is the maximum database size accepted for upload (in MB)

View Source
const MaxLicenceSize = 1

MaxLicenceSize is the maximum licence size accepted for upload (in MB)

View Source
const MinioFolderChars = 6

MinioFolderChars is the number of leading characters of a files' sha256 used as the Minio folder name eg: When set to 6, then "34f4255a737156147fbd0a44323a895d18ade79d4db521564d1b0dbb8764cbbc"

-> Minio folder: "34f425"
-> Minio filename: "5a737156147fbd0a44323a895d18ade79d4db521564d1b0dbb8764cbbc"
View Source
const SqliteDebug = 0

SqliteDebug displays some SQLite related debugging information (on the backend), when set to a non-0 value

Variables

View Source
var (
	// JobListenConn is the PG server connection used for receiving PG notifications
	JobListenConn *pgx.Conn

	// JobQueueConn is the PG server connection used for submitting and retrieving jobs
	JobQueueConn *pgpool.Pool

	// JobQueueDebug tells the daemons whether or not to output debug messages while running job queue code
	// Mostly useful for development / debugging purposes.  0 means no debug messages, higher values means more verbosity
	JobQueueDebug = 0
)
View Source
var (
	// AmqpChan is the AMQP channel handle we use for communication with our AMQP backend
	AmqpChan *amqp.Channel

	// UseAMQP switches between running in AMQP mode (true) or job queue server mode (false)
	UseAMQP = false
)
View Source
var (
	// CheckJobQueue is used by the live daemons for triggering a check of the job queue
	CheckJobQueue chan struct{}

	// CheckResponsesQueue is used by the non-live daemons for triggering a check of the job responses queue
	CheckResponsesQueue chan struct{}

	// ResponseQueue is used to direct job queue responses back to the appropriate callers
	ResponseQueue *ResponseReceivers

	// SubmitterInstance is a random string generated at server start for identification purposes
	SubmitterInstance string
)
View Source
var SQLiteFunctions = []function{}/* 139 elements not displayed */

SQLiteFunctions lists the function we allow SQL queries to run

View Source
var (

	// Validate is used for input validation
	Validate *valid.Validate
)

Functions

func APIKeyDelete added in v0.0.15

func APIKeyDelete(loggedInUser, uuid string) (err error)

APIKeyDelete deletes an existing API key from the PostgreSQL database

func APIKeySave added in v0.0.6

func APIKeySave(key, loggedInUser string, dateCreated time.Time, expiryDate *time.Time, comment string) (uuid string, err error)

APIKeySave saves a new API key to the PostgreSQL database

func AddDatabase

func AddDatabase(loggedInUser, dbOwner, dbName string, createBranch bool, branchName,
	commitID string, accessType SetAccessType, licenceName, commitMsg, sourceURL string, newDB io.Reader,
	lastModified, commitTime time.Time, authorName, authorEmail, committerName, committerEmail string,
	otherParents []string, dbSha string) (numBytes int64, newCommitID string, calculatedDbSha string, err error)

AddDatabase is handles database upload processing

func AddDefaultLicences

func AddDefaultLicences() (err error)

AddDefaultLicences adds the default licences to the PostgreSQL database. Generally useful for populating a new database, or adding new entries to an existing one

func AddDefaultUser

func AddDefaultUser() error

AddDefaultUser adds the default user to the system, so the referential integrity of licence user_id 0 works

func AddUser

func AddUser(auth0ID, userName, password, email, displayName, avatarURL string) error

AddUser adds a user to the system

func AnalysisRecordUserStorage added in v0.0.15

func AnalysisRecordUserStorage(userName string, recordDate time.Time, spaceUsedStandard, spaceUsedLive int64) (err error)

AnalysisRecordUserStorage adds a record to the backend database containing the amount of storage space used by a user

func AnalysisUsersWithDBs added in v0.0.15

func AnalysisUsersWithDBs() (userList map[string]int, err error)

AnalysisUsersWithDBs returns the list of users with at least one database

func ApiCallLog added in v0.0.15

func ApiCallLog(loggedInUser, dbOwner, dbName, operation, callerSw string)

ApiCallLog records an API call operation. Database name is optional, as not all API calls operate on a database. If a database name is provided however, then the database owner name *must* also be provided

func AuthorizerLive added in v0.0.15

func AuthorizerLive(d interface{}, action sqlite.Action, tableName, funcName, dbName, triggerName string) sqlite.Auth

AuthorizerLive is a SQLite authorizer callback intended to allow almost anything. Except for loading extensions, and running pragmas.

func AuthorizerSelect added in v0.0.6

func AuthorizerSelect(d interface{}, action sqlite.Action, tableName, funcName, dbName, triggerName string) sqlite.Auth

AuthorizerSelect is a SQLite authorizer callback which only allows SELECT queries and their needed sub-operations to run.

func CacheData

func CacheData(cacheKey string, cacheData interface{}, cacheSeconds int) error

CacheData caches data in Memcached

func CheckDBExists

func CheckDBExists(dbOwner, dbName string) (bool, error)

CheckDBExists checks if a database exists. It does NOT perform any permission checks. If an error occurred, the true/false value should be ignored, as only the error value is valid

func CheckDBID

func CheckDBID(dbOwner string, dbID int64) (avail bool, dbName string, err error)

CheckDBID checks if a given database ID is available, and returns its name so the caller can determine if it has been renamed. If an error occurs, the true/false value should be ignored, as only the error value is valid

func CheckDBLive added in v0.0.15

func CheckDBLive(dbOwner, dbName string) (isLive bool, liveNode string, err error)

CheckDBLive checks if the given database is a live database

func CheckDBPermissions added in v0.0.15

func CheckDBPermissions(loggedInUser, dbOwner, dbName string, writeAccess bool) (bool, error)

CheckDBPermissions checks if a database exists and can be accessed by the given user. If an error occurred, the true/false value should be ignored, as only the error value is valid

func CheckDBStarred

func CheckDBStarred(loggedInUser, dbOwner, dbName string) (bool, error)

CheckDBStarred check if a database has been starred by a given user. The boolean return value is only valid when err is nil

func CheckDBWatched

func CheckDBWatched(loggedInUser, dbOwner, dbName string) (bool, error)

CheckDBWatched checks if a database is being watched by a given user. The boolean return value is only valid when err is nil

func CheckEmailExists

func CheckEmailExists(email string) (bool, error)

CheckEmailExists checks if an email address already exists in our system. Returns true if the email is already in the system, false if not. If an error occurred, the true/false value should be ignored, as only the error value is valid

func CheckLicenceExists added in v0.0.5

func CheckLicenceExists(userName, licenceName string) (exists bool, err error)

CheckLicenceExists checks if a given licence exists in our system

func CheckUnicode added in v0.0.6

func CheckUnicode(rawInput string, decodeBase64 bool) (str string, err error)

CheckUnicode checks if a given string is unicode, and safe for using in SQLite queries (eg no SQLite control characters)

func CheckUserExists

func CheckUserExists(userName string) (bool, error)

CheckUserExists checks if a username already exists in our system. Returns true if the username is already taken, false if not. If an error occurred, the true/false value should be ignored, and only the error return code used

func ClearCache added in v0.0.15

func ClearCache() (err error)

ClearCache removes all items currently cached by Memcached, so it's like a newly started server

func CloseMQChannel added in v0.0.15

func CloseMQChannel(channel *amqp.Channel) (err error)

CloseMQChannel closes an open AMQP channel

func CloseMQConnection added in v0.0.15

func CloseMQConnection(connection *amqp.Connection) (err error)

CloseMQConnection closes an open AMQP connection

func CommitLicenceSHA

func CommitLicenceSHA(dbOwner, dbName, commitID string) (licenceSHA string, err error)

CommitLicenceSHA returns the licence used by the database in a given commit

func CommitPublicFlag added in v0.0.15

func CommitPublicFlag(loggedInUser, dbOwner, dbName, commitID string) (public bool, err error)

CommitPublicFlag returns the public flag of a given commit

func ConnectCache

func ConnectCache() error

ConnectCache connects to the Memcached server

func ConnectMinio

func ConnectMinio() (err error)

ConnectMinio parses the Minio configuration, to ensure it seems workable Note - this doesn't actually open a connection to the Minio server.

func ConnectPostgreSQL

func ConnectPostgreSQL() (err error)

ConnectPostgreSQL creates a connection pool to the PostgreSQL server

func ConnectQueue added in v0.0.15

func ConnectQueue() (channel *amqp.Channel, err error)

ConnectQueue creates the connections to the backend queue server

func CreateCommitID

func CreateCommitID(c CommitEntry) string

CreateCommitID generate a stable SHA256 for a commit

func CreateDBTreeID

func CreateDBTreeID(entries []DBTreeEntry) string

CreateDBTreeID generate the SHA256 for a tree Tree entry structure is: * [ entry type ] [ licence sha256] [ file sha256 ] [ file name ] [ last modified (timestamp) ] [ file size (bytes) ]

func CreateRelease added in v0.2.1

func CreateRelease(dbOwner, dbName, releaseName, releaseDescription, releaserName, releaserEmail, commitID string) (err error)

CreateRelease is used for creating a release when running tests

func CreateTag added in v0.2.1

func CreateTag(dbOwner, dbName, tagName, tagDescription, taggerName, taggerEmail, commitID string) (err error)

CreateTag is used for creating a tag when running tests

func CypressSeed added in v0.0.15

func CypressSeed(w http.ResponseWriter, r *http.Request)

CypressSeed empties the backend database, then adds pre-defined test data (PostgreSQL and Minio)

func DBDetails

func DBDetails(DB *SQLiteDBinfo, loggedInUser, dbOwner, dbName, commitID string) (err error)

DBDetails returns the details for a specific database

func DBStars

func DBStars(dbOwner, dbName string) (starCount int, err error)

DBStars returns the star count for a given database

func DBWatchers

func DBWatchers(dbOwner, dbName string) (watcherCount int, err error)

DBWatchers returns the watchers count for a given database

func DataValuesMatch added in v0.0.15

func DataValuesMatch(a []DataValue, b []DataValue) (equal bool)

DataValuesMatch compares two slices of DataValue objects. It returns true if the two are equal, false otherwise.

func DefaultCommit

func DefaultCommit(dbOwner, dbName string) (commitID string, err error)

DefaultCommit returns the default commit ID for a specific database

func DeleteBranchHistory

func DeleteBranchHistory(dbOwner, dbName, branchName, commitID string) (isolatedTags, isolatedRels []string, err error)

DeleteBranchHistory safely removes the commit history for a branch, from the head of the branch back to (but not including) the specified commit. The new branch head will be at the commit ID specified

func DeleteComment

func DeleteComment(dbOwner, dbName string, discID, comID int) error

DeleteComment deletes a specific comment from a discussion

func DeleteDatabase

func DeleteDatabase(dbOwner, dbName string) error

DeleteDatabase deletes a database from PostgreSQL Note that we leave a stub/placeholder entry for all uploaded databases in PG, so our stats don't miss data over time and so the dependant table data doesn't go weird. We also set the "is_deleted" boolean to true for its entry, so our database query functions know to skip it

func DeleteLicence added in v0.0.5

func DeleteLicence(userName, licenceName string) (err error)

DeleteLicence removes a (user supplied) database licence from the system

func DisconnectPostgreSQL

func DisconnectPostgreSQL()

DisconnectPostgreSQL disconnects the PostgreSQL database connections

func DownloadDatabase added in v0.0.9

func DownloadDatabase(w http.ResponseWriter, r *http.Request, dbOwner, dbName, commitID,
	loggedInUser, sourceSw string) (bytesWritten int64, err error)

DownloadDatabase returns the SQLite database file to the requester

func EnvProd added in v0.0.15

func EnvProd(w http.ResponseWriter, r *http.Request)

EnvProd changes the running environment to be "production" NOTE - This route to call this is only available when the server is _started_ in the "test" environment

func EnvTest added in v0.0.15

func EnvTest(w http.ResponseWriter, r *http.Request)

EnvTest changes the running environment to be "test" NOTE - This route to call this is only available when the server is _started_ in the "test" environment

func EscapeId added in v0.0.6

func EscapeId(id string) string

EscapeId puts an SQL identifier in quote characters and escapes any quote characters it contains, making it safe for use in SQL queries

func EscapeIds added in v0.0.7

func EscapeIds(ids []string) (escaped []string)

EscapeIds does the same as EscapeId but for a slice of identifiers

func EscapeValue added in v0.0.6

func EscapeValue(val DataValue) string

EscapeValue formats, quotes and escapes a DataValue for use in SQL queries

func EscapeValues added in v0.0.7

func EscapeValues(vals []DataValue) (escaped []string)

EscapeValues does the same as EscapeValue but for a slice of DataValues

func FlushViewCount

func FlushViewCount()

FlushViewCount periodically flushes the database view count from Memcache to PostgreSQL

func ForkDatabase

func ForkDatabase(srcOwner, dbName, dstOwner string) (newForkCount int, err error)

ForkDatabase forks the PostgreSQL entry for a SQLite database from one user to another

func ForkParent

func ForkParent(loggedInUser, dbOwner, dbName string) (parentOwner, parentDBName string, err error)

ForkParent returns the parent of a database, if there is one (and it's accessible to the logged in user). If no parent was found, the returned Owner/DBName values will be empty strings

func ForkedFrom

func ForkedFrom(dbOwner, dbName string) (forkOwn, forkDB string, forkDel bool, err error)

ForkedFrom checks if the given database was forked from another, and if so returns that one's owner and database name

func GenerateClientCert

func GenerateClientCert(userName string) (_ []byte, err error)

GenerateClientCert generates a new DBHub.io client certificate for the given user

func GetAPIKeyUser added in v0.0.6

func GetAPIKeyUser(key string) (user string, err error)

GetAPIKeyUser returns the owner of a given API key. Returns an empty string if the key has no known owner

func GetBranches

func GetBranches(dbOwner, dbName string) (branches map[string]BranchEntry, err error)

GetBranches load the branch heads for a database TODO: It might be better to have the default branch name be returned as part of this list, by indicating in the list TODO which of the branches is the default.

func GetCachedData

func GetCachedData(cacheKey string, cacheData interface{}) (bool, error)

GetCachedData retrieves cached data from Memcached

func GetCommitList

func GetCommitList(dbOwner, dbName string) (map[string]CommitEntry, error)

GetCommitList returns the full commit list for a database

func GetCurrentFunctionName

func GetCurrentFunctionName() (FuncName string)

GetCurrentFunctionName returns the name of the function this was called from

func GetDatabase

func GetDatabase(r *http.Request, allowGet bool) (dbName string, err error)

GetDatabase extracts a database name from GET or POST/PUT data

func GetDefaultBranchName

func GetDefaultBranchName(dbOwner, dbName string) (branchName string, err error)

GetDefaultBranchName returns the default branch name for a database

func GetDefaultTableName

func GetDefaultTableName(dbOwner, dbName string) (tableName string, err error)

GetDefaultTableName returns the default table name for a database

func GetDiscussionAndMRCount

func GetDiscussionAndMRCount(dbOwner, dbName string) (discCount, mrCount int, err error)

GetDiscussionAndMRCount returns the discussion and merge request counts for a database TODO: The only reason this function exists atm, is because we're incorrectly caching the discussion and MR data in TODO a way that makes invalidating it correctly hard/impossible. We should redo our memcached approach to solve the TODO issue properly

func GetFormBranch

func GetFormBranch(r *http.Request) (branch string, err error)

GetFormBranch return the requested branch name, from get or post data

func GetFormCommit

func GetFormCommit(r *http.Request) (commitID string, err error)

GetFormCommit returns the requested database commit, from form data

func GetFormLicence

func GetFormLicence(r *http.Request) (licenceName string, err error)

GetFormLicence returns the licence name (if any) present in the form data

func GetFormLive added in v0.0.15

func GetFormLive(r *http.Request) (live bool, err error)

GetFormLive returns the "live" value (if any) present in the form data

func GetFormODC added in v0.0.6

func GetFormODC(r *http.Request) (userName string, dbName string, commitID string, err error)

GetFormODC returns the database owner, database name, and commit (if any) present in the form data

func GetFormOwner added in v0.0.6

func GetFormOwner(r *http.Request, allowGet bool) (dbOwner string, err error)

GetFormOwner returns the database owner present in the GET or POST/PUT data

func GetFormRelease

func GetFormRelease(r *http.Request) (release string, err error)

GetFormRelease returns the requested release name, from get or post data

func GetFormSourceURL

func GetFormSourceURL(r *http.Request) (sourceURL string, err error)

GetFormSourceURL returns the source URL (if any) present in the form data

func GetFormTable added in v0.0.6

func GetFormTable(r *http.Request, allowGet bool) (table string, err error)

GetFormTable returns the table name present in the GET or POST/PUT data

func GetFormTag

func GetFormTag(r *http.Request) (tag string, err error)

GetFormTag returns the requested tag name, from get or post data

func GetFormUDC

func GetFormUDC(r *http.Request) (userName string, dbName string, commitID string, err error)

GetFormUDC returns the username, database, and commit (if any) present in the form data

func GetLicence

func GetLicence(userName, licenceName string) (txt, format string, err error)

GetLicence returns the text for a given licence

func GetLicenceInfoFromSha256

func GetLicenceInfoFromSha256(userName, sha256 string) (lName, lURL string, err error)

GetLicenceInfoFromSha256 returns the friendly name + licence URL for the licence matching a given sha256 Note - When user defined licence has the same sha256 as a default one we return the user defined licences' friendly name

func GetLicenceSha256FromName

func GetLicenceSha256FromName(userName, licenceName string) (sha256 string, err error)

GetLicenceSha256FromName returns the sha256 for a given licence

func GetLicences

func GetLicences(user string) (map[string]LicenceEntry, error)

GetLicences returns the list of licences available to a user

func GetOD

func GetOD(ignoreLeading int, r *http.Request) (dbOwner string, dbName string, err error)

GetOD returns the requested database owner and database name

func GetODC

func GetODC(ignoreLeading int, r *http.Request) (dbOwner string, dbName string, commitID string, err error)

GetODC returns the requested database owner, database name, and commit revision

func GetODT

func GetODT(ignoreLeading int, r *http.Request) (dbOwner string, dbName string, requestedTable string, err error)

GetODT returns the requested database owner, database name, and table name

func GetODTC

func GetODTC(ignoreLeading int, r *http.Request) (dbOwner string, dbName string, requestedTable string, commitID string, err error)

GetODTC returns the requested database owner, database name, table name, and commit string

func GetPrimaryKeyAndOtherColumns added in v0.0.7

func GetPrimaryKeyAndOtherColumns(sdb *sqlite.Conn, schema, table string) (pks []string, implicitPk bool, other []string, err error)

GetPrimaryKeyAndOtherColumns figures out the primary key columns and the other columns of a table. The schema and table parameters specify the schema and table names to use. This function returns two arrays: One containing the list of primary key columns in the same order as they are used in the primary key. The other array contains a list of all the other, non-primary key columns. Generated columns are ignored completely. If the primary key exists only implicitly, i.e. it's the rowid column, the implicitPk flag is set to true.

func GetPub

func GetPub(r *http.Request) (public bool, err error)

GetPub returns the requested "public" variable, if present in the form data If something goes wrong, it defaults to "false".

func GetReleases

func GetReleases(dbOwner, dbName string) (releases map[string]ReleaseEntry, err error)

GetReleases returns the list of releases for a database

func GetSQLiteRowCount

func GetSQLiteRowCount(sdb *sqlite.Conn, dbTable string) (rowCount int, err error)

GetSQLiteRowCount returns the number of rows in a SQLite table.

func GetShares added in v0.0.15

func GetShares(dbOwner, dbName string) (shares map[string]ShareDatabasePermissions, err error)

GetShares returns a map with all users for which the given database is shared as key and their permissions as value.

func GetTable

func GetTable(r *http.Request) (requestedTable string, err error)

GetTable returns the requested table name (if any)

func GetTags

func GetTags(dbOwner, dbName string) (tags map[string]TagEntry, err error)

GetTags returns the tags for a database

func GetUFD

func GetUFD(r *http.Request, allowGet bool) (userName string, dbFolder string, dbName string, err error)

GetUFD returns the username, folder, and database name (if any) present in the form data

func GetUsername

func GetUsername(r *http.Request, allowGet bool) (userName string, err error)

GetUsername returns the username (if any) present in the GET or POST/PUT data

func GetUsernameFromEmail

func GetUsernameFromEmail(email string) (userName, avatarURL string, err error)

GetUsernameFromEmail returns the username associated with an email address

func GetViewCount

func GetViewCount(dbOwner string, dbName string) (count int, err error)

GetViewCount retrieves the view count in Memcached for a database

func GetVisualisations added in v0.0.6

func GetVisualisations(dbOwner, dbName string) (visualisations map[string]VisParamsV2, err error)

GetVisualisations returns the saved visualisations for a given database

func HttpErrorLog added in v0.0.15

func HttpErrorLog() *log.Logger

HttpErrorLog is used to filter out the copious 'TLS handshake error' messages we're getting

func IncrementDownloadCount

func IncrementDownloadCount(dbOwner, dbName string) error

IncrementDownloadCount increments the download count for a database

func IncrementViewCount

func IncrementViewCount(dbOwner string, dbName string) error

IncrementViewCount increments the view counter in Memcached for a database

func InvalidateCacheEntry

func InvalidateCacheEntry(loggedInUser string, dbOwner string, dbName string, commitID string) error

InvalidateCacheEntry invalidate Memcache data for a database entry or entries

func IsCommitInBranchHistory

func IsCommitInBranchHistory(dbOwner, dbName, branchName, commitID string) (bool, error)

IsCommitInBranchHistory checks if a given commit ID is in the history of the given branch

func JobQueueCheck added in v0.0.15

func JobQueueCheck()

JobQueueCheck checks if newly submitted work is available for processing

func JobQueueCreateDatabase added in v0.0.15

func JobQueueCreateDatabase(req JobRequest) (err error)

JobQueueCreateDatabase creates a database on a live node

func JobQueueErrorString added in v0.0.15

func JobQueueErrorString(errCode JobQueueErrorCode) string

func JobQueueGetSize added in v0.0.15

func JobQueueGetSize(DBOwner, DBName string) (size int64, err error)

JobQueueGetSize returns the on disk size of a database on a live node

func JobQueueListen added in v0.0.15

func JobQueueListen()

JobQueueListen listens for database notify events indicating newly submitted jobs

func JobSubmit added in v0.0.15

func JobSubmit[T any](response *T, targetNode, operation, requestingUser, dbOwner, dbName string, data interface{}) (err error)

JobSubmit submits job details to our PostgreSQL based job queue

func LiveAddDatabasePG added in v0.0.15

func LiveAddDatabasePG(dbOwner, dbName, bucketName, liveNode string, accessType SetAccessType) (err error)

LiveAddDatabasePG adds the details for a live database to PostgreSQL

func LiveBackup added in v0.0.15

func LiveBackup(liveNode, loggedInUser, dbOwner, dbName string) (err error)

LiveBackup asks the job queue backend to store the given database back into Minio

func LiveColumns added in v0.0.15

func LiveColumns(liveNode, loggedInUser, dbOwner, dbName, table string) (columns []sqlite.Column, pk []string, err error)

LiveColumns requests the job queue backend to return a list of all columns of the given table

func LiveCreateDB added in v0.0.15

func LiveCreateDB(channel *amqp.Channel, dbOwner, dbName, objectID string) (liveNode string, err error)

LiveCreateDB requests the job queue backend create a new live SQLite database

func LiveDelete added in v0.0.15

func LiveDelete(liveNode, loggedInUser, dbOwner, dbName string) (err error)

LiveDelete asks our job queue backend to delete a database

func LiveExecute added in v0.0.15

func LiveExecute(liveNode, loggedInUser, dbOwner, dbName, sql string) (rowsChanged int, err error)

LiveExecute asks our job queue backend to execute a SQL statement on a database

func LiveGenerateMinioNames added in v0.0.15

func LiveGenerateMinioNames(userName string) (bucketName, objectName string, err error)

LiveGenerateMinioNames generates Minio bucket and object names for a live database

func LiveGetMinioNames added in v0.0.15

func LiveGetMinioNames(loggedInUser, dbOwner, dbName string) (bucketName, objectName string, err error)

LiveGetMinioNames retrieves the Minio bucket and object names for a live database

func LiveRetrieveDatabaseMinio added in v0.0.15

func LiveRetrieveDatabaseMinio(baseDir, dbOwner, dbName, objectID string) (dbPath string, err error)

LiveRetrieveDatabaseMinio retrieves a live SQLite database from Minio, and places it on the local filesystem

func LiveSize added in v0.0.15

func LiveSize(liveNode, loggedInUser, dbOwner, dbName string) (size int64, err error)

LiveSize asks our job queue backend for the file size of a database

func LiveSqlHistoryAdd added in v0.0.15

func LiveSqlHistoryAdd(loggedInUser, dbOwner, dbName, stmt string, state SqlHistoryItemStates, result interface{}) (err error)

LiveSqlHistoryAdd adds a new record to the history of recently executed SQL statements

func LiveSqlHistoryDeleteOld added in v0.0.15

func LiveSqlHistoryDeleteOld(loggedInUser, dbOwner, dbName string, keepRecords int) (err error)

LiveSqlHistoryDeleteOld deletes all saved SQL statements in the SQL history table, except for the most recent ones

func LiveStoreDatabaseMinio added in v0.0.15

func LiveStoreDatabaseMinio(db *os.File, dbOwner, dbName string, dbSize int64) (minioObjectID string, err error)

LiveStoreDatabaseMinio stores a live SQLite database in Minio

func LiveTables added in v0.0.15

func LiveTables(liveNode, loggedInUser, dbOwner, dbName string) (tables []string, err error)

LiveTables asks our job queue backend to provide the list of tables (not including views!) in a database

func LiveTablesAndViews added in v0.0.15

func LiveTablesAndViews(liveNode, loggedInUser, dbOwner, dbName string) (list []string, err error)

LiveTablesAndViews asks our job queue backend to provide the list of tables and views in a database

func LiveViews added in v0.0.15

func LiveViews(liveNode, loggedInUser, dbOwner, dbName string) (views []string, err error)

LiveViews asks our job queue backend to provide the list of views (not including tables!) in a database

func LogDB4SConnect added in v0.0.6

func LogDB4SConnect(userAcc, ipAddr, userAgent string, downloadDate time.Time) error

LogDB4SConnect creates a DB4S default browse list entry

func LogDownload

func LogDownload(dbOwner, dbName, loggedInUser, ipAddr, serverSw, userAgent string, downloadDate time.Time, sha string) error

LogDownload creates a download log entry

func LogSQLiteQueryAfter added in v0.0.6

func LogSQLiteQueryAfter(insertID, memUsed, memHighWater int64) (err error)

LogSQLiteQueryAfter adds memory allocation stats for the execution run of a user supplied SQLite query

func LogSQLiteQueryBefore added in v0.0.6

func LogSQLiteQueryBefore(source, dbOwner, dbName, loggedInUser, ipAddr, userAgent, query string) (int64, error)

LogSQLiteQueryBefore logs the basic info for a user supplied SQLite query

func LogUpload

func LogUpload(dbOwner, dbName, loggedInUser, ipAddr, serverSw, userAgent string, uploadDate time.Time, sha string) error

LogUpload creates an upload log entry

func MQCreateDBQueue added in v0.0.15

func MQCreateDBQueue(channel *amqp.Channel) (queue amqp.Queue, err error)

MQCreateDBQueue creates a queue on the MQ server for "create database" messages

func MQCreateQueryQueue added in v0.0.15

func MQCreateQueryQueue(channel *amqp.Channel, nodeName string) (queue amqp.Queue, err error)

MQCreateQueryQueue creates a queue on the MQ server for sending database queries to

func MQCreateResponse added in v0.0.15

func MQCreateResponse(msg amqp.Delivery, channel *amqp.Channel, nodeName, result string) (err error)

MQCreateResponse sends a success/failure response back

func MQRequest added in v0.0.15

func MQRequest(channel *amqp.Channel, queue, operation, requestingUser, dbOwner, dbName string, data interface{}) (result []byte, err error)

MQRequest is the main function used for sending requests to our AMQP backend

func MQResponse added in v0.0.15

func MQResponse(requestType string, msg amqp.Delivery, channel *amqp.Channel, nodeName string, responseData interface{}) (err error)

MQResponse sends an AMQP response back to its requester

func MemcacheHandle

func MemcacheHandle() *memcache.Client

MemcacheHandle returns the Memcached handle

func Merge added in v0.0.15

func Merge(destOwner, destName, destBranch, srcOwner, srcName string, commitDiffList []CommitEntry, message, loggedInUser string) (newCommitID string, err error)

Merge merges the commits in commitDiffList into the destination branch destBranch of the given database

func MetadataCacheKey

func MetadataCacheKey(prefix string, loggedInUser string, dbOwner string, dbName string, commitID string) string

MetadataCacheKey generates a predictable cache key for metadata information

func MinioDeleteDatabase added in v0.0.15

func MinioDeleteDatabase(source, dbOwner, dbName, bucket, id string) (err error)

MinioDeleteDatabase deletes a database file from Minio

func MinioHandle

func MinioHandle(bucket, id string) (*minio.Object, error)

MinioHandle gets a handle from Minio for a SQLite database object

func MinioHandleClose

func MinioHandleClose(userDB *minio.Object) (err error)

MinioHandleClose closes a Minio object handle. Probably most useful for calling with defer()

func MinioLocation

func MinioLocation(dbOwner, dbName, commitID, loggedInUser string) (minioBucket, minioID string, lastModified time.Time, err error)

MinioLocation returns the Minio bucket and ID for a given database. dbOwner & dbName are from owner/database URL fragment, loggedInUser is the name for the currently logged in user, for access permission check. Use an empty string ("") as the loggedInUser parameter if the true value isn't set or known. If the requested database doesn't exist, or the loggedInUser doesn't have access to it, then an error will be returned

func NewEvent

func NewEvent(details EventDetails) (err error)

NewEvent adds an event entry to PostgreSQL

func OpenSQLiteDatabase added in v0.0.6

func OpenSQLiteDatabase(bucket, id string) (sdb *sqlite.Conn, err error)

OpenSQLiteDatabase retrieves a SQLite database from Minio, opens it, then returns the connection handle.

func OpenSQLiteDatabaseDefensive added in v0.0.6

func OpenSQLiteDatabaseDefensive(w http.ResponseWriter, r *http.Request, dbOwner, dbName, commitID, loggedInUser string) (sdb *sqlite.Conn, err error)

OpenSQLiteDatabaseDefensive is similar to OpenSQLiteDatabase(), but opens the database Read Only and implements the recommended defensive precautions for potentially malicious user provided SQL queries: https://www.sqlite.org/security.html

func OpenSQLiteDatabaseLive added in v0.0.15

func OpenSQLiteDatabaseLive(baseDir, dbOwner, dbName string) (sdb *sqlite.Conn, err error)

OpenSQLiteDatabaseLive is similar to OpenSQLiteDatabase(), but opens the a live SQLite database and implements the recommended defensive precautions for potentially malicious user provided SQL queries: https://www.sqlite.org/security.html TODO: De-duplicate/refactor the common code in this function and OpenSQLiteDatabaseDefensive() above, as they're TODO mostly the same

func PrefUserMaxRows

func PrefUserMaxRows(loggedInUser string) int

PrefUserMaxRows returns the user's preference for maximum number of SQLite rows to display.

func RandomString

func RandomString(length int) string

RandomString generates a random alphanumeric string of the desired length

func ReadConfig

func ReadConfig() (err error)

ReadConfig reads the server configuration file.

func ReadSQLiteDBCSV

func ReadSQLiteDBCSV(sdb *sqlite.Conn, dbTable string) ([][]string, error)

ReadSQLiteDBCSV is a specialised variation of the ReadSQLiteDB() function, just for our CSV exporting code. It may be merged with that in future.

func RecordWebLogin added in v0.0.15

func RecordWebLogin(userName string) (err error)

RecordWebLogin records the start time of a user login session, for stats purposes

func RemoveLiveDB added in v0.0.15

func RemoveLiveDB(dbOwner, dbName string) (err error)

RemoveLiveDB deletes a live database from the local node. For example, when the user deletes it from their account. Be aware, it leaves the database owners directory in place, to avoid any potential race condition of trying to delete that directory while other databases in their account are being worked with

func RenameDatabase

func RenameDatabase(userName, dbName, newName string) error

RenameDatabase renames a SQLite database

func ReservedUsernamesCheck

func ReservedUsernamesCheck(userName string) error

ReservedUsernamesCheck checks a username against the list of reserved ones

func ResetDB added in v0.0.15

func ResetDB() error

ResetDB resets the database to its default state. eg for testing purposes

func ResponseComplete added in v0.0.15

func ResponseComplete(responseID int) (err error)

ResponseComplete marks a response as processed

func ResponseQueueCheck added in v0.0.15

func ResponseQueueCheck()

ResponseQueueCheck checks if a newly submitted response is available for processing

func ResponseQueueListen added in v0.0.15

func ResponseQueueListen()

ResponseQueueListen listens for database notify events with responses from the other DBHub.io daemons

func ResponseSubmit added in v0.0.15

func ResponseSubmit(jobID int, submitterNode string, payload []byte) (err error)

ResponseSubmit adds a response to the job_responses table

func RetrieveDatabaseFile added in v0.0.6

func RetrieveDatabaseFile(bucket, id string) (newDB string, err error)

RetrieveDatabaseFile retrieves a SQLite database file from Minio. If there's a locally cached version already available though, use that

func SQLiteBackupLive added in v0.0.15

func SQLiteBackupLive(baseDir, dbOwner, dbName string) (err error)

SQLiteBackupLive is used by our job queue backend nodes to refresh a live SQLite database back into Minio

func SQLiteExecuteQueryLive added in v0.0.15

func SQLiteExecuteQueryLive(baseDir, dbOwner, dbName, loggedInUser, query string) (rowsChanged int, err error)

SQLiteExecuteQueryLive is used by our job queue backend infrastructure to execute a user provided SQLite statement

func SQLiteGetTablesLive added in v0.0.15

func SQLiteGetTablesLive(baseDir, dbOwner, dbName string) (tables []string, err error)

SQLiteGetTablesLive is used by our job queue backend nodes to retrieve the list of tables in a SQLite database

func SQLiteGetViewsLive added in v0.0.15

func SQLiteGetViewsLive(baseDir, dbOwner, dbName string) (views []string, err error)

SQLiteGetViewsLive is used by our job queue backend nodes to retrieve the list of views in a SQLite database

func SQLiteSanityCheck added in v0.0.15

func SQLiteSanityCheck(fileName string) (tables []string, err error)

SQLiteSanityCheck performs basic sanity checks of an uploaded database.

func SQLiteVersionNumber added in v0.0.6

func SQLiteVersionNumber() int32

SQLiteVersionNumber returns the version number of the available SQLite library, in 300X00Y format.

func SanitiseLogString added in v0.0.15

func SanitiseLogString(v string) (result string)

func SaveDBSettings

func SaveDBSettings(userName, dbName, oneLineDesc, fullDesc, defaultTable string, public bool, sourceURL, defaultBranch string) error

SaveDBSettings saves updated database settings to PostgreSQL

func SendEmails

func SendEmails()

SendEmails sends status update emails to people watching databases

func SetClientCert

func SetClientCert(newCert []byte, userName string) error

SetClientCert stores a certificate for a given client

func SetUserPreferences

func SetUserPreferences(userName string, maxRows int, displayName, email string) error

SetUserPreferences sets the user's preference for maximum number of SQLite rows to display

func SetUserStatusUpdates

func SetUserStatusUpdates(userName string, numUpdates int) error

SetUserStatusUpdates increments the view counter in Memcached for a database

func SignalHandler added in v0.0.15

func SignalHandler(done *chan struct{})

SignalHandler is a background goroutine that exists to catch *nix termination signals then shut the daemon down cleanly

func SocialStats

func SocialStats(dbOwner, dbName string) (wa, st, fo int, err error)

SocialStats returns the latest social stats for a given database

func StatusUpdateCheck

func StatusUpdateCheck(dbOwner, dbName string, thisID int, userName string) (numStatusUpdates int, err error)

StatusUpdateCheck checks if a status update for the user exists for a given discussion or MR, and if so then removes it

func StatusUpdates

func StatusUpdates(loggedInUser string) (statusUpdates map[string][]StatusUpdateEntry, err error)

StatusUpdates returns the list of outstanding status updates for a user

func StatusUpdatesLoop

func StatusUpdatesLoop()

StatusUpdatesLoop periodically generates status updates (alert emails TBD) from the event queue

func StoreBranches

func StoreBranches(dbOwner, dbName string, branches map[string]BranchEntry) error

StoreBranches updates the branches list for a database

func StoreComment

func StoreComment(dbOwner, dbName, commenter string, discID int, comText string, discClose bool, mrState MergeRequestState) error

StoreComment adds a comment to a discussion

func StoreCommits

func StoreCommits(dbOwner, dbName string, commitList map[string]CommitEntry) error

StoreCommits updates the commit list for a database

func StoreDatabase

func StoreDatabase(dbOwner, dbName string, branches map[string]BranchEntry, c CommitEntry, pub bool,
	buf *os.File, sha string, dbSize int64, oneLineDesc, fullDesc string, createDefBranch bool, branchName,
	sourceURL string) error

StoreDatabase stores database details in PostgreSQL, and the database data itself in Minio

func StoreDatabaseFile

func StoreDatabaseFile(db *os.File, sha string, dbSize int64) error

StoreDatabaseFile stores a database file in Minio

func StoreDefaultBranchName

func StoreDefaultBranchName(dbOwner, dbName, branchName string) error

StoreDefaultBranchName stores the default branch name for a database

func StoreDefaultTableName

func StoreDefaultTableName(dbOwner, dbName, tableName string) error

StoreDefaultTableName stores the default table name for a database

func StoreDiscussion

func StoreDiscussion(dbOwner, dbName, loggedInUser, title, text string, discType DiscussionType,
	mr MergeRequestEntry) (newID int, err error)

StoreDiscussion stores a new discussion for a database

func StoreLicence

func StoreLicence(userName, licenceName string, txt []byte, url string, orderNum int, fullName, fileFormat string) error

StoreLicence stores a licence

func StoreReleases

func StoreReleases(dbOwner, dbName string, releases map[string]ReleaseEntry) error

StoreReleases stores the releases for a database

func StoreShares added in v0.0.15

func StoreShares(dbOwner, dbName string, shares map[string]ShareDatabasePermissions) (err error)

StoreShares stores the shares of a database

func StoreStatusUpdates

func StoreStatusUpdates(userName string, statusUpdates map[string][]StatusUpdateEntry) error

StoreStatusUpdates stores the status updates list for a user

func StoreTags

func StoreTags(dbOwner, dbName string, tags map[string]TagEntry) error

StoreTags stores the tags for a database

func SwitchDefault added in v0.0.15

func SwitchDefault(w http.ResponseWriter, r *http.Request)

SwitchDefault changes the logged in user to be the user "default"

func SwitchFirst added in v0.0.15

func SwitchFirst(w http.ResponseWriter, r *http.Request)

SwitchFirst changes the logged in user to be the test user "first"

func SwitchSecond added in v0.0.15

func SwitchSecond(w http.ResponseWriter, r *http.Request)

SwitchSecond changes the logged in user to be the test user "second"

func SwitchThird added in v0.0.15

func SwitchThird(w http.ResponseWriter, r *http.Request)

SwitchThird changes the logged in user to be the test user "third"

func TableRowsCacheKey

func TableRowsCacheKey(prefix string, loggedInUser string, dbOwner string, dbName string, commitID string, dbTable string, rows int) string

TableRowsCacheKey generates a predictable cache key for SQLite row data. ONLY for standard databases

func Tables

func Tables(sdb *sqlite.Conn) (tbl []string, err error)

Tables returns the list of tables in the SQLite database.

func TablesAndViews added in v0.0.6

func TablesAndViews(sdb *sqlite.Conn, dbName string) (list []string, err error)

TablesAndViews returns the list of tables and views in the SQLite database.

func TestLogout added in v0.0.15

func TestLogout(w http.ResponseWriter, r *http.Request)

TestLogout logs out the user for test runs

func ToggleDBStar

func ToggleDBStar(loggedInUser, dbOwner, dbName string) error

ToggleDBStar toggles the starring of a database by a user

func ToggleDBWatch

func ToggleDBWatch(loggedInUser, dbOwner, dbName string) error

ToggleDBWatch toggles the watch status of a database by a user

func UpdateAvatarURL

func UpdateAvatarURL(userName, avatarURL string) error

UpdateAvatarURL updates the Avatar URL for a user

func UpdateComment

func UpdateComment(dbOwner, dbName, loggedInUser string, discID, comID int, newText string) error

UpdateComment updates the text for a comment

func UpdateContributorsCount

func UpdateContributorsCount(dbOwner, dbName string) error

UpdateContributorsCount updates the contributors count for a database

func UpdateDiscussion

func UpdateDiscussion(dbOwner, dbName, loggedInUser string, discID int, newTitle, newText string) error

UpdateDiscussion updates the text for a discussion

func UpdateMergeRequestCommits

func UpdateMergeRequestCommits(dbOwner, dbName string, discID int, mrCommits []CommitEntry) (err error)

UpdateMergeRequestCommits updates the commit list for a Merge Request

func UpdateModified added in v0.0.15

func UpdateModified(dbOwner, dbName string) (err error)

UpdateModified is a simple function to change the 'last modified' timestamp for a database to now()

func UploadResponse added in v0.0.13

func UploadResponse(w http.ResponseWriter, r *http.Request, loggedInUser, targetUser, targetDB, commitID, serverSw string) (retMsg map[string]string, httpStatus int, err error)

UploadResponse validates incoming upload requests from the db4s and api daemons, then processes the upload

func UserNameFromAuth0ID

func UserNameFromAuth0ID(auth0id string) (string, error)

UserNameFromAuth0ID returns the username for a given Auth0 ID

func UserStatusUpdates

func UserStatusUpdates(userName string) (numUpdates int, err error)

UserStatusUpdates returns the number of status updates outstanding for a user

func ValidateBranchName

func ValidateBranchName(fieldName string) error

ValidateBranchName validates the provided branch, release, or tag name

func ValidateCommitID added in v0.0.5

func ValidateCommitID(fieldName string) error

ValidateCommitID validates the provided commit ID

func ValidateDB

func ValidateDB(dbName string) error

ValidateDB validates the database name

func ValidateDiscussionTitle

func ValidateDiscussionTitle(fieldName string) error

ValidateDiscussionTitle validates the provided discussion or merge request title

func ValidateDisplayName added in v0.0.5

func ValidateDisplayName(dbName string) error

ValidateDisplayName validates a provided full name

func ValidateEmail

func ValidateEmail(email string) error

ValidateEmail validates the provided email address

func ValidateFieldName

func ValidateFieldName(fieldName string) error

ValidateFieldName validates the SQLite field name

func ValidateLicence

func ValidateLicence(licence string) error

ValidateLicence validates the provided licence name (ID)

func ValidateLicenceFullName added in v0.0.5

func ValidateLicenceFullName(licence string) error

ValidateLicenceFullName validate the provided licence full name

func ValidateMarkdown

func ValidateMarkdown(fieldName string) error

ValidateMarkdown validates the provided markdown

func ValidatePGTable

func ValidatePGTable(table string) error

ValidatePGTable validates the provided PostgreSQL table name

func ValidateUser

func ValidateUser(user string) error

ValidateUser validates the provided username

func ValidateUserDB

func ValidateUserDB(user, db string) error

ValidateUserDB validates the provided user and database name

func ValidateUserDBTable

func ValidateUserDBTable(user, db, table string) error

ValidateUserDBTable validates the provided user, database, and table name

func ValidateUserEmail

func ValidateUserEmail(user, email string) error

ValidateUserEmail validates the provided username and email address

func ValidateVisualisationName added in v0.0.15

func ValidateVisualisationName(name string) error

ValidateVisualisationName validates the provided name of a saved visualisation query

func ViewCount

func ViewCount(dbOwner, dbName string) (viewCount int, err error)

ViewCount returns the view counter for a specific database

func Views added in v0.0.6

func Views(sdb *sqlite.Conn) (vw []string, err error)

Views returns the list of views in the SQLite database.

func VisualisationDeleteParams added in v0.0.6

func VisualisationDeleteParams(dbOwner, dbName, visName string) (err error)

VisualisationDeleteParams deletes a set of visualisation parameters

func VisualisationRename added in v0.0.15

func VisualisationRename(dbOwner, dbName, visName, visNewName string) (err error)

VisualisationRename renames an existing saved visualisation

func VisualisationSaveData added in v0.0.6

func VisualisationSaveData(dbOwner, dbName, commitID, hash string, visData []VisRowV1) (err error)

VisualisationSaveData saves visualisation result data for later retrieval

func VisualisationSaveParams added in v0.0.6

func VisualisationSaveParams(dbOwner, dbName, visName string, visParams VisParamsV2) (err error)

VisualisationSaveParams saves a set of visualisation parameters for later retrieval

func WaitForResponse added in v0.0.15

func WaitForResponse[T any](jobID int, resp *T) (err error)

WaitForResponse waits for the job queue server to provide a response for a given job id

func WriteDBtoDisk added in v0.0.15

func WriteDBtoDisk(loggedInUser, dbOwner, dbName string, newDB io.Reader) (numBytes int64, tempDB *os.File, sha string, sTbls []string, err error)

WriteDBtoDisk gets an uploaded database file from the user's incoming request, and writes it to a local temporary file

Types

type APIJSONColumn added in v0.0.6

type APIJSONColumn struct {
	Cid       int    `json:"column_id"`
	Name      string `json:"name"`
	DataType  string `json:"data_type"`
	NotNull   bool   `json:"not_null"`
	DfltValue string `json:"default_value"`
	Pk        int    `json:"primary_key"`
}

APIJSONColumn is a copy of the Column type from github.com/gwenn/gosqlite, but including JSON field name info

type APIJSONIndex added in v0.0.11

type APIJSONIndex struct {
	Name    string               `json:"name"`
	Table   string               `json:"table"`
	Columns []APIJSONIndexColumn `json:"columns"`
}

APIJSONIndex holds the details of an index for a SQLite database. It's used by our API for returning index information

func LiveIndexes added in v0.0.15

func LiveIndexes(liveNode, loggedInUser, dbOwner, dbName string) (indexes []APIJSONIndex, err error)

LiveIndexes asks our job queue backend to provide the list of indexes in a database

func SQLiteGetIndexesLive added in v0.0.15

func SQLiteGetIndexesLive(baseDir, dbOwner, dbName string) (indexes []APIJSONIndex, err error)

SQLiteGetIndexesLive is used by our job queue backend nodes to retrieve the list of indexes from a SQLite database

type APIJSONIndexColumn added in v0.0.11

type APIJSONIndexColumn struct {
	CID  int    `json:"id"`
	Name string `json:"name"`
}

APIJSONIndexColumn holds the details of one column of a SQLite database index. It's used by our API for returning index information

type APIKey added in v0.0.6

type APIKey struct {
	Uuid        string     `json:"uuid"`
	Key         string     `json:"key"`
	DateCreated time.Time  `json:"date_created"`
	ExpiryDate  *time.Time `json:"expiry_date"`
	Comment     string     `json:"comment"`
}

APIKey is an internal structure used for passing around user API keys

func APIKeyGenerate added in v0.0.15

func APIKeyGenerate(loggedInUser string, expiryDate *time.Time, comment string) (key APIKey, err error)

APIKeyGenerate generates a random API key and saves it in the database

func GetAPIKeys added in v0.0.6

func GetAPIKeys(user string) ([]APIKey, error)

GetAPIKeys returns the list of API keys for a user

type AccessType

type AccessType int

AccessType is whether a database is private, or public, or both

const (
	DB_BOTH AccessType = iota
	DB_PRIVATE
	DB_PUBLIC
)

type ActivityRange

type ActivityRange string

type ActivityRow

type ActivityRow struct {
	Count  int    `json:"count"`
	DBName string `json:"dbname"`
	Owner  string `json:"owner"`
}

type ActivityStats

type ActivityStats struct {
	Downloads []ActivityRow
	Forked    []ActivityRow
	Starred   []ActivityRow
	Uploads   []UploadRow
	Viewed    []ActivityRow
}

func GetActivityStats

func GetActivityStats() (stats ActivityStats, err error)

GetActivityStats returns the latest activity stats

type ApiInfo added in v0.0.6

type ApiInfo struct {
	BaseDir        string `toml:"base_dir"`
	BindAddress    string `toml:"bind_address"`
	Certificate    string `toml:"certificate"`
	CertificateKey string `toml:"certificate_key"`
	RequestLog     string `toml:"request_log"`
	ServerName     string `toml:"server_name"`
}

ApiInfo contains configuration info for the API daemon

type Auth0Info

type Auth0Info struct {
	ClientID     string
	ClientSecret string
	Domain       string
}

Auth0Info contains the Auth0 connection info used authenticating webUI users

type BranchEntry

type BranchEntry struct {
	Commit      string `json:"commit"`
	CommitCount int    `json:"commit_count"`
	Description string `json:"description"`
}

type BranchListResponseContainer added in v0.0.8

type BranchListResponseContainer struct {
	Branches      map[string]BranchEntry `json:"branches"`
	DefaultBranch string                 `json:"default_branch"`
}

BranchListResponseContainer holds the response to a client request for the database branch list. It's a temporary structure, mainly so the JSON created for it is consistent between our various daemons

func BranchListResponse added in v0.0.8

func BranchListResponse(dbOwner, dbName string) (list BranchListResponseContainer, err error)

BranchListResponse returns the branch list for a database. It's used by both the DB4S and API daemons, to ensure they return exactly the same data

type CommitData

type CommitData struct {
	AuthorAvatar   string    `json:"author_avatar"`
	AuthorEmail    string    `json:"author_email"`
	AuthorName     string    `json:"author_name"`
	AuthorUsername string    `json:"author_username"`
	ID             string    `json:"id"`
	Parent         string    `json:"parent"`
	LicenceChange  string    `json:"licence_change"`
	Message        string    `json:"message"`
	Timestamp      time.Time `json:"timestamp"`
}

type CommitEntry

type CommitEntry struct {
	AuthorEmail    string    `json:"author_email"`
	AuthorName     string    `json:"author_name"`
	CommitterEmail string    `json:"committer_email"`
	CommitterName  string    `json:"committer_name"`
	ID             string    `json:"id"`
	Message        string    `json:"message"`
	OtherParents   []string  `json:"other_parents"`
	Parent         string    `json:"parent"`
	Timestamp      time.Time `json:"timestamp"`
	Tree           DBTree    `json:"tree"`
}

func GetCommonAncestorCommits

func GetCommonAncestorCommits(srcOwner, srcDBName, srcBranch, destOwner, destName,
	destBranch string) (ancestorID string, commitList []CommitEntry, errType int, err error)

GetCommonAncestorCommits determines the common ancestor commit (if any) between a source and destination branch. Returns the commit ID of the ancestor and a slice of the commits between them. If no common ancestor exists, the returned ancestorID will be an empty string. Created for use by our Merge Request functions.

type DB4SInfo

type DB4SInfo struct {
	CAChain        string `toml:"ca_chain"`
	Certificate    string
	CertificateKey string `toml:"certificate_key"`
	Debug          bool
	Port           int
	Server         string
}

DB4SInfo contains configuration info for the DB4S end point daemon

type DBEntry

type DBEntry struct {
	DateEntry        time.Time
	DBName           string
	Owner            string
	OwnerDisplayName string `json:"display_name"`
}

func UserStarredDBs

func UserStarredDBs(userName string) (list []DBEntry, err error)

UserStarredDBs returns the list of databases starred by a user

func UserWatchingDBs

func UserWatchingDBs(userName string) (list []DBEntry, err error)

UserWatchingDBs returns the list of databases watched by a user

func UsersStarredDB

func UsersStarredDB(dbOwner, dbName string) (list []DBEntry, err error)

UsersStarredDB returns the list of users who starred a database

func UsersWatchingDB

func UsersWatchingDB(dbOwner, dbName string) (list []DBEntry, err error)

UsersWatchingDB returns the list of users watching a database

type DBInfo

type DBInfo struct {
	Branch        string
	Branches      int
	BranchList    []string
	Commits       int
	CommitID      string
	Contributors  int
	Database      string
	DateCreated   time.Time
	DBEntry       DBTreeEntry
	DefaultBranch string
	DefaultTable  string
	Discussions   int
	Downloads     int
	ForkDatabase  string
	ForkDeleted   bool
	ForkOwner     string
	Forks         int
	FullDesc      string
	IsLive        bool
	LastModified  time.Time
	Licence       string
	LicenceURL    string
	LiveNode      string
	MRs           int
	MyStar        bool
	MyWatch       bool
	OneLineDesc   string
	Owner         string
	Public        bool
	RepoModified  time.Time
	Releases      int
	SHA256        string
	Size          int64
	SourceURL     string
	Stars         int
	Tables        []string
	Tags          int
	Views         int
	Watchers      int
}

func LiveUserDBs added in v0.0.15

func LiveUserDBs(dbOwner string, public AccessType) (list []DBInfo, err error)

LiveUserDBs returns the list of live databases owned by the user

func UserDBs

func UserDBs(userName string, public AccessType) (list []DBInfo, err error)

UserDBs returns the list of databases for a user

type DBTree

type DBTree struct {
	ID      string        `json:"id"`
	Entries []DBTreeEntry `json:"entries"`
}

type DBTreeEntry

type DBTreeEntry struct {
	EntryType    DBTreeEntryType `json:"entry_type"`
	LastModified time.Time       `json:"last_modified"`
	LicenceSHA   string          `json:"licence"`
	Name         string          `json:"name"`
	Sha256       string          `json:"sha256"`
	Size         int64           `json:"size"`
}

type DBTreeEntryType

type DBTreeEntryType string

type DataDiff added in v0.0.6

type DataDiff struct {
	ActionType DiffType      `json:"action_type"`
	Sql        string        `json:"sql,omitempty"`
	Pk         []DataValue   `json:"pk"`
	DataBefore []interface{} `json:"data_before,omitempty"`
	DataAfter  []interface{} `json:"data_after,omitempty"`
}

DataDiff stores a single change in the data of a table, i.e. a single new, deleted, or changed row

type DataRow

type DataRow []DataValue

type DataValue

type DataValue struct {
	Name  string
	Type  ValType
	Value interface{}
}

type DatabaseName added in v0.0.15

type DatabaseName struct {
	Database string
	Owner    string
}

type DiffObjectChangeset added in v0.0.6

type DiffObjectChangeset struct {
	ObjectName string      `json:"object_name"`
	ObjectType string      `json:"object_type"`
	Schema     *SchemaDiff `json:"schema,omitempty"`
	Data       []DataDiff  `json:"data,omitempty"`
}

DiffObjectChangeset stores all the differences between two objects in a database, for example two tables. Both Schema and Data are optional and can be nil if there are no respective changes in this object.

type DiffType added in v0.0.6

type DiffType string

DiffType specifies the type of change in a row or object

const (
	// ActionAdd is used for inserted rows and created objects
	ActionAdd DiffType = "add"

	// ActionDelete is used for deleted rows and dropped objects
	ActionDelete DiffType = "delete"

	// ActionModify is used for updated rows and altered objects
	ActionModify DiffType = "modify"
)

type Diffs added in v0.0.6

type Diffs struct {
	Diff []DiffObjectChangeset `json:"diff"`
}

Diffs is able to store all the differences between two databases.

func DBDiff added in v0.0.15

func DBDiff(dbA string, dbB string, merge MergeStrategy, includeData bool) (Diffs, error)

DBDiff generates the differences between the two database files in dbA and dbB

func Diff added in v0.0.6

func Diff(ownerA string, nameA string, commitA string, ownerB string, nameB string, commitB string, loggedInUser string, merge MergeStrategy, includeData bool) (Diffs, error)

Diff generates the differences between the two commits commitA and commitB of the two databases specified in the other parameters

type DiscussionCommentEntry

type DiscussionCommentEntry struct {
	AvatarURL    string                `json:"avatar_url"`
	Body         string                `json:"body"`
	BodyRendered string                `json:"body_rendered"`
	Commenter    string                `json:"commenter"`
	DateCreated  time.Time             `json:"creation_date"`
	EntryType    DiscussionCommentType `json:"entry_type"`
	ID           int                   `json:"com_id"`
}

func DiscussionComments

func DiscussionComments(dbOwner, dbName string, discID, comID int) (list []DiscussionCommentEntry, err error)

DiscussionComments returns the list of comments for a given discussion If a non-0 comID value is passed, it will only return the details for that specific comment in the discussion. Otherwise it will return a list of all comments for a given discussion Note - This returns a slice instead of a map. We use a slice because it lets us use an ORDER BY clause in the SQL and preserve the returned order (maps don't preserve order). If in future we no longer need to preserve the order, it might be useful to switch to using a map instead since they're often simpler to work with.

type DiscussionCommentType

type DiscussionCommentType string

type DiscussionEntry

type DiscussionEntry struct {
	AvatarURL    string            `json:"avatar_url"`
	Body         string            `json:"body"`
	BodyRendered string            `json:"body_rendered"`
	CommentCount int               `json:"comment_count"`
	Creator      string            `json:"creator"`
	DateCreated  time.Time         `json:"creation_date"`
	ID           int               `json:"disc_id"`
	LastModified time.Time         `json:"last_modified"`
	MRDetails    MergeRequestEntry `json:"mr_details"`
	Open         bool              `json:"open"`
	Title        string            `json:"title"`
	Type         DiscussionType    `json:"discussion_type"`
}

func Discussions

func Discussions(dbOwner, dbName string, discType DiscussionType, discID int) (list []DiscussionEntry, err error)

Discussions returns the list of discussions or MRs for a given database If a non-0 discID value is passed, it will only return the details for that specific discussion/MR. Otherwise, it will return a list of all discussions or MRs for a given database Note - This returns a slice of DiscussionEntry, instead of a map. We use a slice because it lets us use an ORDER

BY clause in the SQL and preserve the returned order (maps don't preserve order).  If in future we no longer
need to preserve the order, it might be useful to switch to using a map instead since they're often simpler
to work with.

type DiscussionType

type DiscussionType int
const (
	DISCUSSION    DiscussionType = 0 // These are not iota, as it would be seriously bad for these numbers to change
	MERGE_REQUEST                = 1
)

type DiskCacheInfo

type DiskCacheInfo struct {
	Directory string
}

DiskCacheInfo contains the path to the root of the local disk cache

type EnvInfo

type EnvInfo struct {
	Environment  string
	UserOverride string `toml:"user_override"`
}

EnvInfo holds information about the purpose of the running server. eg "is this a production, docker, or development" instance?

type EventDetails

type EventDetails struct {
	DBName    string    `json:"database_name"`
	DiscID    int       `json:"discussion_id"`
	ID        string    `json:"event_id"`
	Message   string    `json:"message"`
	Owner     string    `json:"database_owner"`
	Timestamp time.Time `json:"event_timestamp"`
	Title     string    `json:"title"`
	Type      EventType `json:"event_type"`
	URL       string    `json:"event_url"`
	UserName  string    `json:"username"`
}

type EventProcessingInfo

type EventProcessingInfo struct {
	Delay                     time.Duration `toml:"delay"`
	EmailQueueProcessingDelay time.Duration `toml:"email_queue_processing_delay"`
	Smtp2GoKey                string        `toml:"smtp2go_key"` // The SMTP2GO API key
}

EventProcessingInfo hold configuration for the event processing loop

type EventType

type EventType int

type ExecuteResponseContainer added in v0.0.15

type ExecuteResponseContainer struct {
	RowsChanged int    `json:"rows_changed"`
	Status      string `json:"status"`
}

ExecuteResponseContainer is used by our job queue backend, to return information in response to an Execute() call on a live database. It holds the success/failure status of the remote call, and also the number of rows changed by the Execute() call (if it succeeded)

type FilteringErrorLogWriter added in v0.0.15

type FilteringErrorLogWriter struct{}

FilteringErrorLogWriter is a custom error logger for our http servers, to filter out the copious 'TLS handshake error' messages we're getting. Very heavily based on: https://github.com/golang/go/issues/26918#issuecomment-974257205

func (*FilteringErrorLogWriter) Write added in v0.0.15

func (*FilteringErrorLogWriter) Write(msg []byte) (int, error)

type ForkEntry

type ForkEntry struct {
	DBName     string     `json:"database_name"`
	ForkedFrom int        `json:"forked_from"`
	IconList   []ForkType `json:"icon_list"`
	ID         int        `json:"id"`
	Owner      string     `json:"database_owner"`
	Processed  bool       `json:"processed"`
	Public     bool       `json:"public"`
	Deleted    bool       `json:"deleted"`
}

func ForkTree

func ForkTree(loggedInUser, dbOwner, dbName string) (outputList []ForkEntry, err error)

ForkTree returns the complete fork tree for a given database

type ForkType

type ForkType int
const (
	SPACE ForkType = iota
	ROOT
	STEM
	BRANCH
	END
)

type JobQueueErrorCode added in v0.0.15

type JobQueueErrorCode int
const (
	JobQueueNoError JobQueueErrorCode = iota
	JobQueueRequestedTableNotPresent
)

func SQLiteGetColumnsLive added in v0.0.15

func SQLiteGetColumnsLive(baseDir, dbOwner, dbName, table string) (columns []sqlite.Column, pk []string, err error, errCode JobQueueErrorCode)

SQLiteGetColumnsLive is used by our job queue backend nodes to retrieve the list of columns from a SQLite database

type JobRequest added in v0.0.15

type JobRequest struct {
	Operation      string      `json:"operation"`
	DBOwner        string      `json:"dbowner"`
	DBName         string      `json:"dbname"`
	Data           interface{} `json:"data,omitempty"`
	RequestingUser string      `json:"requesting_user"`
}

JobRequest holds the fields used for sending requests to our job request backend

type JobRequestRows added in v0.0.15

type JobRequestRows struct {
	DbTable   string `json:"db_table"`
	SortCol   string `json:"sort_col"`
	SortDir   string `json:"sort_dir"`
	CommitID  string `json:"commit_id"`
	RowOffset int    `json:"row_offset"`
	MaxRows   int    `json:"max_rows"`
}

JobRequestRows holds the data used when making a rows request to our job queue backend

type JobResponseDBColumns added in v0.0.15

type JobResponseDBColumns struct {
	Columns   []sqlite.Column   `json:"columns"`
	Err       string            `json:"error"`
	ErrCode   JobQueueErrorCode `json:"error_code"`
	PkColumns []string          `json:"pkColumns"`
}

JobResponseDBColumns holds the fields used for receiving column list responses from our job queue backend

type JobResponseDBCreate added in v0.0.15

type JobResponseDBCreate struct {
	Err      string `json:"error"`
	NodeName string `json:"node_name"`
}

JobResponseDBCreate holds the fields used for receiving database creation responses from our job queue backend

type JobResponseDBError added in v0.0.15

type JobResponseDBError struct {
	Err string `json:"error"`
}

JobResponseDBError holds the structure used when our job queue backend only needs to response with an error field (empty or not)

type JobResponseDBExecute added in v0.0.15

type JobResponseDBExecute struct {
	Err         string `json:"error"`
	RowsChanged int    `json:"rows_changed"`
}

JobResponseDBExecute holds the fields used for receiving the database execute response from our job queue backend

type JobResponseDBIndexes added in v0.0.15

type JobResponseDBIndexes struct {
	Err     string         `json:"error"`
	Indexes []APIJSONIndex `json:"indexes"`
}

JobResponseDBIndexes holds the fields used for receiving the database index list from our job queue backend

type JobResponseDBQuery added in v0.0.15

type JobResponseDBQuery struct {
	Err     string          `json:"error"`
	Results SQLiteRecordSet `json:"results"`
}

JobResponseDBQuery holds the fields used for receiving database query results from our job queue backend

type JobResponseDBRows added in v0.0.15

type JobResponseDBRows struct {
	DatabaseSize int64           `json:"database_size"`
	DefaultTable string          `json:"default_table"`
	Err          string          `json:"error"`
	RowData      SQLiteRecordSet `json:"row_data"`
	Tables       []string        `json:"tables"`
}

JobResponseDBRows holds the fields used for receiving table row data from our job queue backend

type JobResponseDBSize added in v0.0.15

type JobResponseDBSize struct {
	Err  string `json:"error"`
	Size int64  `json:"size"`
}

JobResponseDBSize holds the fields used for receiving database size responses from our job queue backend

type JobResponseDBTables added in v0.0.15

type JobResponseDBTables struct {
	Err    string   `json:"error"`
	Tables []string `json:"tables"`
}

JobResponseDBTables holds the fields used for receiving the database table list from our job queue backend

type JobResponseDBViews added in v0.0.15

type JobResponseDBViews struct {
	Err   string   `json:"error"`
	Views []string `json:"views"`
}

JobResponseDBViews holds the fields used for receiving the database views list from our job queue backend

type JsonError added in v0.0.6

type JsonError struct {
	Error string `json:"error"`
}

JsonError holds the details of an error. It's used by our API for returning error information

type LicenceEntry

type LicenceEntry struct {
	FileFormat string `json:"file_format"`
	FullName   string `json:"full_name"`
	Order      int    `json:"order"`
	Sha256     string `json:"sha256"`
	URL        string `json:"url"`
}

type LicenceInfo added in v0.0.5

type LicenceInfo struct {
	LicenceDir string `toml:"licence_dir"`
}

LicenceInfo -> LicenceDir holds the path to the licence files

type LiveDBColumnsResponse added in v0.0.15

type LiveDBColumnsResponse struct {
	Node      string            `json:"node"`
	Columns   []sqlite.Column   `json:"columns"`
	PkColumns []string          `json:"pkColuns"`
	Error     string            `json:"error"`
	ErrCode   JobQueueErrorCode `json:"error_code"`
}

LiveDBColumnsResponse holds the fields used for receiving column list responses from our AMQP backend

type LiveDBErrorResponse added in v0.0.15

type LiveDBErrorResponse struct {
	Node  string `json:"node"`
	Error string `json:"error"`
}

LiveDBErrorResponse holds just the node name and any error message used in responses by our AMQP backend It's useful for error message, and other responses where no other fields are needed

type LiveDBExecuteResponse added in v0.0.15

type LiveDBExecuteResponse struct {
	Node        string `json:"node"`
	RowsChanged int    `json:"rows_changed"`
	Error       string `json:"error"`
}

LiveDBExecuteResponse returns the number of rows changed by an Execute() call

type LiveDBIndexesResponse added in v0.0.15

type LiveDBIndexesResponse struct {
	Node    string         `json:"node"`
	Indexes []APIJSONIndex `json:"indexes"`
	Error   string         `json:"error"`
}

LiveDBIndexesResponse holds the fields used for receiving index list responses from our AMQP backend

type LiveDBQueryResponse added in v0.0.15

type LiveDBQueryResponse struct {
	Node    string          `json:"node"`
	Results SQLiteRecordSet `json:"results"`
	Error   string          `json:"error"`
}

LiveDBQueryResponse holds the fields used for receiving query responses from our AMQP backend

type LiveDBRequest added in v0.0.15

type LiveDBRequest struct {
	Operation      string      `json:"operation"`
	DBOwner        string      `json:"dbowner"`
	DBName         string      `json:"dbname"`
	Data           interface{} `json:"data,omitempty"`
	RequestingUser string      `json:"requesting_user"`
}

LiveDBRequest holds the fields used for sending requests to our AMQP backend

type LiveDBResponse added in v0.0.15

type LiveDBResponse struct {
	Node   string `json:"node"`
	Result string `json:"result"`
	Error  string `json:"error"`
}

LiveDBResponse holds the fields used for receiving (non-query) responses from our AMQP backend

type LiveDBRowsRequest added in v0.0.15

type LiveDBRowsRequest struct {
	DbTable   string `json:"db_table"`
	SortCol   string `json:"sort_col"`
	SortDir   string `json:"sort_dir"`
	CommitID  string `json:"commit_id"`
	RowOffset int    `json:"row_offset"`
	MaxRows   int    `json:"max_rows"`
}

LiveDBRowsRequest holds the data used when making an AMQP rows request

type LiveDBRowsResponse added in v0.0.15

type LiveDBRowsResponse struct {
	Node         string          `json:"node"`
	DatabaseSize int64           `json:"database_size"`
	DefaultTable string          `json:"default_table"`
	Error        string          `json:"error"`
	RowData      SQLiteRecordSet `json:"row_data"`
	Tables       []string        `json:"tables"`
}

LiveDBRowsResponse holds the fields used for receiving database page row responses from our AMQP backend

type LiveDBSizeResponse added in v0.0.15

type LiveDBSizeResponse struct {
	Node  string `json:"node"`
	Size  int64  `json:"size"`
	Error string `json:"error"`
}

LiveDBSizeResponse holds the fields used for receiving database size responses from our AMQP backend

type LiveDBTablesResponse added in v0.0.15

type LiveDBTablesResponse struct {
	Node   string   `json:"node"`
	Tables []string `json:"tables"`
	Error  string   `json:"error"`
}

LiveDBTablesResponse holds the fields used for receiving table list responses from our AMQP backend

type LiveDBViewsResponse added in v0.0.15

type LiveDBViewsResponse struct {
	Node  string   `json:"node"`
	Views []string `json:"views"`
	Error string   `json:"error"`
}

LiveDBViewsResponse holds the fields used for receiving view list responses from our AMQP backend

type LiveInfo added in v0.0.15

type LiveInfo struct {
	Nodename   string `toml:"node_name"`
	StorageDir string `toml:"storage_dir"`
}

LiveInfo holds configuration info for the Live database daemon

type MQInfo added in v0.0.15

type MQInfo struct {
	CertFile string `toml:"cert_file"`
	KeyFile  string `toml:"key_file"`
	Password string `toml:"password"`
	Port     int    `toml:"port"`
	Server   string `toml:"server"`
	Username string `toml:"username"`
}

type MemcacheInfo

type MemcacheInfo struct {
	DefaultCacheTime    int           `toml:"default_cache_time"`
	Server              string        `toml:"server"`
	ViewCountFlushDelay time.Duration `toml:"view_count_flush_delay"`
}

MemcacheInfo contains the Memcached configuration parameters

type MergeRequestEntry

type MergeRequestEntry struct {
	Commits      []CommitEntry     `json:"commits"`
	DestBranch   string            `json:"destination_branch"`
	SourceBranch string            `json:"source_branch"`
	SourceDBID   int64             `json:"source_database_id"`
	SourceDBName string            `json:"source_database_name"`
	SourceOwner  string            `json:"source_owner"`
	State        MergeRequestState `json:"state"`
}

type MergeRequestState

type MergeRequestState int

type MergeStrategy added in v0.0.7

type MergeStrategy int

MergeStrategy specifies the type of SQL statements included in the diff results. The SQL statements can be used for merging databases and depending on whether and how you want to merge you should choose your merge strategy.

const (
	// NoMerge removes any SQL statements for merging from the diff results
	NoMerge MergeStrategy = iota

	// PreservePkMerge produces SQL statements which preserve the values of the primary key columns.
	// Executing these statements on the first database produces a database similar to the second.
	PreservePkMerge

	// NewPkMerge produces SQL statements which generate new values for the primary key columns when
	// executed. This avoids a couple of possible conflicts and allows merging more distant databases.
	NewPkMerge
)

type MetadataResponseContainer added in v0.0.8

type MetadataResponseContainer struct {
	Branches  map[string]BranchEntry  `json:"branches"`
	Commits   map[string]CommitEntry  `json:"commits"`
	DefBranch string                  `json:"default_branch"`
	Releases  map[string]ReleaseEntry `json:"releases"`
	Tags      map[string]TagEntry     `json:"tags"`
	WebPage   string                  `json:"web_page"`
}

MetadataResponseContainer holds the response to a client request for database metadata. It's a temporary structure, mainly so the JSON created for it is consistent between our various daemons

func MetadataResponse added in v0.0.8

func MetadataResponse(dbOwner, dbName string) (meta MetadataResponseContainer, err error)

MetadataResponse returns the metadata for a database. It's used by both the DB4S and API daemons, to ensure they return exactly the same data

type MinioInfo

type MinioInfo struct {
	AccessKey string `toml:"access_key"`
	HTTPS     bool
	Secret    string
	Server    string
}

MinioInfo contains the Minio connection parameters

type PGInfo

type PGInfo struct {
	Database       string
	NumConnections int `toml:"num_connections"`
	Port           int
	Password       string
	Server         string
	SSL            bool
	Username       string
}

PGInfo contains the PostgreSQL connection parameters

type QuerySource added in v0.0.6

type QuerySource int

QuerySource is used internally to help choose the output format from a SQL query

const (
	QuerySourceDB4S QuerySource = iota
	QuerySourceVisualisation
	QuerySourceAPI
	QuerySourceInternal
)

type ReleaseEntry

type ReleaseEntry struct {
	Commit        string    `json:"commit"`
	Date          time.Time `json:"date"`
	Description   string    `json:"description"`
	ReleaserEmail string    `json:"email"`
	ReleaserName  string    `json:"name"`
	Size          int64     `json:"size"`
}

type ResponseInfo added in v0.0.15

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

ResponseInfo holds job queue responses. Most of the useful info is json encoded in the payload field

type ResponseReceivers added in v0.0.15

type ResponseReceivers struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

ResponseReceivers is a simple structure used for matching up job queue responses to the caller who submitted the job

func NewResponseQueue added in v0.0.15

func NewResponseQueue() *ResponseReceivers

NewResponseQueue is the constructor function for creating a new ResponseReceivers

func (*ResponseReceivers) AddReceiver added in v0.0.15

func (r *ResponseReceivers) AddReceiver(jobID int, newReceiver *chan ResponseInfo)

AddReceiver adds a new response receiver

func (*ResponseReceivers) RemoveReceiver added in v0.0.15

func (r *ResponseReceivers) RemoveReceiver(jobID int)

RemoveReceiver removes a response receiver (generally after it has received the response it was waiting for)

type SQLiteDBinfo

type SQLiteDBinfo struct {
	Info     DBInfo
	MaxRows  int
	MinioBkt string
	MinioId  string
}

type SQLiteRecordSet

type SQLiteRecordSet struct {
	ColCount          int
	ColNames          []string
	Offset            int
	PrimaryKeyColumns []string `json:"primaryKeyColumns,omitempty"`
	Records           []DataRow
	RowCount          int
	SortCol           string
	SortDir           string
	Tablename         string
	TotalRows         int
}

func LiveQuery added in v0.0.15

func LiveQuery(liveNode, loggedInUser, dbOwner, dbName, query string) (rows SQLiteRecordSet, err error)

LiveQuery sends a SQLite query to a live database on its hosting node

func LiveRowData added in v0.0.15

func LiveRowData(liveNode, loggedInUser, dbOwner, dbName string, reqData JobRequestRows) (rowData SQLiteRecordSet, err error)

LiveRowData asks our job queue backend to send us the SQLite table data for a given range of rows

func ReadSQLiteDB

func ReadSQLiteDB(sdb *sqlite.Conn, dbTable, sortCol, sortDir string, maxRows, rowOffset int) (SQLiteRecordSet, error)

ReadSQLiteDB reads up to maxRows number of rows from a given SQLite database table. If maxRows < 0 (eg -1), then read all rows.

func ReadSQLiteDBCols

func ReadSQLiteDBCols(sdb *sqlite.Conn, dbTable, sortCol, sortDir string, ignoreBinary, ignoreNull bool, maxRows, rowOffset int) (SQLiteRecordSet, error)

ReadSQLiteDBCols reads up to maxRows # of rows from a SQLite database. Only returns the requested columns.

func SQLiteReadDatabasePage added in v0.0.15

func SQLiteReadDatabasePage(bucket, id, loggedInUser, dbOwner, dbName, dbTable, sortCol, sortDir, commitID string, rowOffset, maxRows int, isLive bool) (tables []string, defaultTable string, rowData SQLiteRecordSet, dbSize int64, err error)

SQLiteReadDatabasePage opens a SQLite database (locally) and returns a "page" of rows from it, for display in the database view page. Note that the dbSize return value is only set for live databases.

func SQLiteRunQuery added in v0.0.6

func SQLiteRunQuery(sdb *sqlite.Conn, querySource QuerySource, dbQuery string, ignoreBinary, ignoreNull bool) (memUsed, memHighWater int64, dataRows SQLiteRecordSet, err error)

SQLiteRunQuery runs a SQLite query. DO NOT use this for user provided SQL queries. For those, use SQLiteRunQueryDefensive().

func SQLiteRunQueryDefensive added in v0.0.6

func SQLiteRunQueryDefensive(w http.ResponseWriter, r *http.Request, querySource QuerySource, dbOwner, dbName, commitID, loggedInUser, query string) (SQLiteRecordSet, error)

SQLiteRunQueryDefensive runs a user provided SQLite query, using our "defensive" mode. eg with limits placed on what it's allowed to do.

func SQLiteRunQueryLive added in v0.0.15

func SQLiteRunQueryLive(baseDir, dbOwner, dbName, loggedInUser, query string) (records SQLiteRecordSet, err error)

SQLiteRunQueryLive is used by our job queue backend infrastructure to run a user provided SQLite query

type SchemaDiff added in v0.0.6

type SchemaDiff struct {
	ActionType DiffType `json:"action_type"`
	Sql        string   `json:"sql,omitempty"`
	Before     string   `json:"before"`
	After      string   `json:"after"`
}

SchemaDiff describes the changes to the schema of a database object, i.e. a created, dropped or altered object

type SetAccessType added in v0.0.15

type SetAccessType int

SetAccessType is used for setting the public flag of a database

const (
	SetToPublic SetAccessType = iota
	SetToPrivate
	KeepCurrentAccessType
)

type SetDBType added in v0.0.15

type SetDBType int

SetDBType is used for setting what type of database we're working with

const (
	DBTypeStandard SetDBType = iota
	DBTypeLive
)

type ShareDatabasePermissions added in v0.0.15

type ShareDatabasePermissions string
const (
	MayRead         ShareDatabasePermissions = "r"
	MayReadAndWrite ShareDatabasePermissions = "rw"
)

type ShareDatabasePermissionsOthers added in v0.0.15

type ShareDatabasePermissionsOthers struct {
	DBName string                              `json:"database_name"`
	IsLive bool                                `json:"is_live"`
	Perms  map[string]ShareDatabasePermissions `json:"user_permissions"`
}

ShareDatabasePermissionsOthers contains a list of user permissions for a given database

type ShareDatabasePermissionsUser added in v0.0.15

type ShareDatabasePermissionsUser struct {
	OwnerName  string                   `json:"owner_name"`
	DBName     string                   `json:"database_name"`
	IsLive     bool                     `json:"is_live"`
	Permission ShareDatabasePermissions `json:"permission"`
}

ShareDatabasePermissionsUser contains a list of shared database permissions for a given user

func GetSharesForUser added in v0.0.15

func GetSharesForUser(userName string) (shares []ShareDatabasePermissionsUser, err error)

GetSharesForUser returns a list of all the databases shared with the given user, and their permissions.

type SigningInfo

type SigningInfo struct {
	CertDaysValid    int    `toml:"cert_days_valid"`
	Enabled          bool   `toml:"enabled"`
	IntermediateCert string `toml:"intermediate_cert"`
	IntermediateKey  string `toml:"intermediate_key"`
}

SigningInfo contains the info used for signing DB4S client certificates

type SqlHistoryItem added in v0.0.15

type SqlHistoryItem struct {
	Statement string               `json:"input"`
	Result    interface{}          `json:"output"`
	State     SqlHistoryItemStates `json:"state"`
}

func LiveSqlHistoryGet added in v0.0.15

func LiveSqlHistoryGet(loggedInUser, dbOwner, dbName string) (history []SqlHistoryItem, err error)

LiveSqlHistoryGet returns the list of recently executed SQL statement for a user and database

type SqlHistoryItemStates added in v0.0.15

type SqlHistoryItemStates string
const (
	Executed SqlHistoryItemStates = "executed"
	Queried  SqlHistoryItemStates = "queried"
	Error    SqlHistoryItemStates = "error"
)

type StatusResponseContainer added in v0.0.14

type StatusResponseContainer struct {
	Status string `json:"status"`
}

StatusResponseContainer holds a general status message response to a client request.

type StatusUpdateEntry

type StatusUpdateEntry struct {
	DiscID int    `json:"discussion_id"`
	Title  string `json:"title"`
	URL    string `json:"event_url"`
}

type TagEntry

type TagEntry struct {
	Commit      string    `json:"commit"`
	Date        time.Time `json:"date"`
	Description string    `json:"description"`
	TaggerEmail string    `json:"email"`
	TaggerName  string    `json:"name"`
}

type TomlConfig

type TomlConfig struct {
	Api         ApiInfo
	Auth0       Auth0Info
	DB4S        DB4SInfo
	Environment EnvInfo
	DiskCache   DiskCacheInfo
	Event       EventProcessingInfo
	Licence     LicenceInfo
	Live        LiveInfo
	Memcache    MemcacheInfo
	Minio       MinioInfo
	MQ          MQInfo
	Pg          PGInfo
	Sign        SigningInfo
	UserMgmt    UserMgmtInfo
	Web         WebInfo
}

TomlConfig is a top level structure containing the server configuration information

var (
	// Conf holds our configuration info
	Conf TomlConfig
)

type UploadResponseContainer added in v0.0.13

type UploadResponseContainer struct {
	CommitID string `json:"commit"`
	URL      string `json:"url"`
}

UploadResponseContainer holds the response to a client upload. It's a temporary structure, mainly so the JSON created for it is consistent between our various daemons

type UploadRow

type UploadRow struct {
	DBName     string    `json:"dbname"`
	Owner      string    `json:"owner"`
	UploadDate time.Time `json:"upload_date"`
}

type UserDetails

type UserDetails struct {
	AvatarURL   string
	ClientCert  []byte
	DateJoined  time.Time
	DisplayName string
	Email       string
	MinioBucket string
	Password    string
	PHash       []byte
	PVerify     string
	Username    string
}

func User

func User(userName string) (user UserDetails, err error)

User returns details for a user

type UserInfo

type UserInfo struct {
	FullName     string `json:"full_name"`
	LastModified time.Time
	Username     string
}

type UserInfoSlice added in v0.0.6

type UserInfoSlice []UserInfo

UserInfoSlice is used for sorting a UserInfo list by Last Modified date descending

func DB4SDefaultList

func DB4SDefaultList(loggedInUser string) (UserInfoSlice, error)

DB4SDefaultList returns a list of 1) users with public databases, 2) along with the logged in users' most recently modified database (including their private one(s))

func (UserInfoSlice) Len added in v0.0.6

func (u UserInfoSlice) Len() int

func (UserInfoSlice) Less added in v0.0.6

func (u UserInfoSlice) Less(i, j int) bool

func (UserInfoSlice) Swap added in v0.0.6

func (u UserInfoSlice) Swap(i, j int)

type UserMgmtInfo added in v0.0.15

type UserMgmtInfo struct {
	BannedUsers       []string `toml:"banned_users"`        // List of users banned from the service
	SizeOverrideUsers []string `toml:"size_override_users"` // List of users allowed to override the database upload size limits
}

UserMgmtInfo contains the various settings for specific users, or groups of users

type ValType

type ValType int

ValType indicates the type of data in a field returned from a SQLite query

const (
	Binary ValType = iota
	Image
	Null
	Text
	Integer
	Float
)

type VisGetFields added in v0.0.6

type VisGetFields struct {
	VisName string `validate:"required,visname,min=1,max=63"` // 63 char limit seems reasonable
}

VisGetFields is used when validating input

type VisParamsV2 added in v0.0.6

type VisParamsV2 struct {
	ChartType   string `json:"chart_type"`
	ShowXLabel  bool   `json:"show_x_label"`
	ShowYLabel  bool   `json:"show_y_label"`
	SQL         string `json:"sql"`
	XAXisColumn string `json:"x_axis_label"`
	YAXisColumn string `json:"y_axis_label"`
}

type VisRowV1 added in v0.0.6

type VisRowV1 struct {
	Name  string
	Value int
}

type WebInfo

type WebInfo struct {
	BaseDir              string `toml:"base_dir"`
	BindAddress          string `toml:"bind_address"`
	Certificate          string `toml:"certificate"`
	CertificateKey       string `toml:"certificate_key"`
	RequestLog           string `toml:"request_log"`
	ServerName           string `toml:"server_name"`
	SessionStorePassword string `toml:"session_store_password"`
}

WebInfo contains configuration info for the webUI daemon

type WebpageResponseContainer added in v0.0.12

type WebpageResponseContainer struct {
	WebPage string `json:"web_page"`
}

WebpageResponseContainer holds the response to a client request for the database webUI URL. It's a temporary structure, mainly so the JSON created for it is consistent between our various daemons

type WhereClause

type WhereClause struct {
	Column string
	Type   string
	Value  string
}

Jump to

Keyboard shortcuts

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