docdb

package module
v0.0.0-...-3ac79f6 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2025 License: MIT Imports: 23 Imported by: 1

README

go-docdb

Experimental, do not use!

Copyright (c) 2021 by DOMONDA GmbH

Documentation

Index

Constants

View Source
const ErrNoChanges errs.Sentinel = "no changes"

ErrNoChanges is returned when a new document version has no changes compared to the previous version.

View Source
const (
	// VersionTimeFormat is the string format of a version time
	// returned by VersionTime.String() and parsed by VersionTimeFromString.
	VersionTimeFormat = "2006-01-02_15-04-05.000"
)

Variables

This section is empty.

Functions

func AddDocumentVersion

func AddDocumentVersion(ctx context.Context, docID, userID uu.ID, reason string, createVersion CreateVersionFunc, onNewVersion OnNewVersionFunc) (err error)

AddDocumentVersion adds a new version to a document using the files returned by createVersion. Returns a wrapped ErrNoChanges if the files returned by createVersion are the same as the latest version.

func CheckConnDocumentVersionFiles

func CheckConnDocumentVersionFiles(ctx context.Context, conn Conn, docID uu.ID, version VersionTime, expectedFiles []fs.FileReader) (err error)

func CheckedOutDocumentDir

func CheckedOutDocumentDir(docID uu.ID) fs.File

CheckedOutDocumentDir returns a fs.File for the directory where a document would be checked out.

func Configure

func Configure(db Conn)

Configure the database connection

func ContentHash

func ContentHash(data []byte) string

ContentHash returns a Dropbox compatible 64 hex character content hash for the passed data.

See https://www.dropbox.com/developers/reference/content-hash

func ContextWithVersionTime

func ContextWithVersionTime(parent context.Context, version VersionTime) context.Context

ContextWithVersionTime returns a new context with the passed version time added to it.

This is useful in combination with NewVersionTime(ctx) for deterministic versions in unit tests.

func CopyAllCompanyDocumentFiles

func CopyAllCompanyDocumentFiles(ctx context.Context, conn Conn, companyID uu.ID, backupDir fs.File, overwrite bool) (docDirs []fs.File, err error)

CopyAllCompanyDocumentFiles copies the files of all versions of all documents of a company to a backup directory.

The backupDir must exist and a directory structures for the documents will be created inside the backupDir and returned as docDirs. In case of an error the already backed up documents will be returned as docDirs.

If true is passed for overwrite then existing files will be overwritten else an error is reeturned when docDir already exists.

func CopyDocumentFiles

func CopyDocumentFiles(ctx context.Context, conn Conn, docID uu.ID, backupDir fs.File, overwrite bool) (destDocDir fs.File, err error)

CopyDocumentFiles copies the files of all versions of a document to a backup directory.

The backupDir must exist and a directory structure for the docID will be created inside the backupDir and returned as docDir.

If true is passed for overwrite then existing files will be overwritten else an error is reeturned when docDir already exists.

In case of an error the already created directories and files will be removed.

func DeleteDocument

func DeleteDocument(ctx context.Context, docID uu.ID) (err error)

DeleteDocument deletes all versions of a document including its workspace directory if checked out.

func DocumentCompanyID

func DocumentCompanyID(ctx context.Context, docID uu.ID) (companyID uu.ID, err error)

DocumentCompanyID returns the companyID for a docID

func DocumentExists

func DocumentExists(ctx context.Context, docID uu.ID) (exists bool, err error)

DocumentExists returns true if a document with the passed docID exists

func DocumentFileExists

func DocumentFileExists(ctx context.Context, docID uu.ID, filename string) (exists bool, err error)

DocumentFileExists returns if a document file with filename exists in the latest document version.

func DocumentVersionFileReader

func DocumentVersionFileReader(ctx context.Context, docID uu.ID, version VersionTime, filename string) (fileReader fs.FileReader, err error)

DocumentVersionFileReader returns a fs.FileReader for a file of a document version. Wrapped ErrDocumentNotFound, ErrDocumentVersionNotFound, ErrDocumentFileNotFound will be returned in case of such error conditions.

func EnumCompanyDocumentIDs

func EnumCompanyDocumentIDs(ctx context.Context, companyID uu.ID, callback func(context.Context, uu.ID) error) (err error)

EnumCompanyDocumentIDs calls the passed callback with the ID of every document of a company in the database

func EnumDocumentIDs

func EnumDocumentIDs(ctx context.Context, callback func(context.Context, uu.ID) error) (err error)

EnumDocumentIDs calls the passed callback with the ID of every document in the database

func FirstDocumentVersionCommitUserID

func FirstDocumentVersionCommitUserID(ctx context.Context, docID uu.ID) (userID uu.ID, err error)

func IdenticalDocumentVersionsOfDrivers

func IdenticalDocumentVersionsOfDrivers(ctx context.Context, docID uu.ID, driverA Conn, versionA VersionTime, driverB Conn, versionB VersionTime) (identical bool, err error)

func IsErrDocumentCheckedOutByUser

func IsErrDocumentCheckedOutByUser(err error, userID uu.ID) bool

func PostgresDeleteDocumentVersionByID

func PostgresDeleteDocumentVersionByID(ctx context.Context, versionID uu.ID) (err error)

func PostgresGetDocumentVersionIDOrNull

func PostgresGetDocumentVersionIDOrNull(ctx context.Context, documentID uu.ID, version VersionTime) (id uu.NullableID, err error)

func PostgresGetDocumentVersionIDs

func PostgresGetDocumentVersionIDs(ctx context.Context, documentID uu.ID) (ids uu.IDSlice, err error)

func PostgresInsertDocumentVersionIfMissing

func PostgresInsertDocumentVersionIfMissing(ctx context.Context, versionInfo *VersionInfo) (versionID uu.ID, didExist bool, err error)

PostgresInsertDocumentVersionIfMissing inserts the document information if there is no existing one

func PostgresInsertDocumentVersionWithFiles

func PostgresInsertDocumentVersionWithFiles(ctx context.Context, versionID uu.ID, versionInfo *VersionInfo) (err error)

func ReadDocumentVersionFile

func ReadDocumentVersionFile(ctx context.Context, docID uu.ID, version VersionTime, filename string) (data []byte, err error)

ReadDocumentVersionFile returns the contents of a file of a document version. Wrapped ErrDocumentNotFound, ErrDocumentVersionNotFound, ErrDocumentFileNotFound will be returned in case of such error conditions.

func ReadMemFile

func ReadMemFile(ctx context.Context, provider FileProvider, filename string) (fs.MemFile, error)

ReadMemFile reads a file from a FileProvider and returns it as an fs.MemFile.

func SetDocumentCompanyID

func SetDocumentCompanyID(ctx context.Context, docID, companyID uu.ID) (err error)

SetDocumentCompanyID changes the companyID for a document

func TempFileCopy

func TempFileCopy(ctx context.Context, provider FileProvider, filename string) (fs.File, error)

TempFileCopy reads a file from a FileProvider and writes it to a temporary file with a random basename and the same extension as the original filename.

func ToRefactorVersionExists

func ToRefactorVersionExists(ctx context.Context, documentID uu.ID, version VersionTime) (exists bool, err error)

Types

type CheckOutStatus

type CheckOutStatus struct {
	CompanyID   uu.ID
	DocID       uu.ID
	Version     VersionTime
	UserID      uu.ID
	Reason      string
	Time        time.Time
	CheckOutDir fs.File
}

func CheckOutDocument

func CheckOutDocument(ctx context.Context, docID, userID uu.ID, reason string) (status *CheckOutStatus, err error)

CheckOutDocument checks out a document for a user with a stated reason. Returns ErrDocumentCheckedOut if the document is already checked out.

func CheckOutNewDocument

func CheckOutNewDocument(ctx context.Context, docID, companyID, userID uu.ID, reason string) (status *CheckOutStatus, err error)

CheckOutNewDocument creates a new document for a company in checked out state.

func CheckedOutDocuments

func CheckedOutDocuments(ctx context.Context) (stati []*CheckOutStatus, err error)

CheckedOutDocuments returns the CheckOutStatus of all checked out documents.

func DocumentCheckOutStatus

func DocumentCheckOutStatus(ctx context.Context, docID uu.ID) (status *CheckOutStatus, err error)

DocumentCheckOutStatus returns the CheckOutStatus of a document. If the document is not checked out, then a nil CheckOutStatus will be returned. The methods Valid() and String() can be called on a nil CheckOutStatus. ErrDocumentNotFound is returned if the document does not exist.

func (*CheckOutStatus) String

func (s *CheckOutStatus) String() string

String implements the fmt.Stringer interface.

func (*CheckOutStatus) Valid

func (s *CheckOutStatus) Valid() bool

type Conn

type Conn interface {
	// DocumentExists returns true if a document with the passed docID exists in
	DocumentExists(ctx context.Context, docID uu.ID) (exists bool, err error)

	// EnumDocumentIDs calls the passed callback with the ID of every document in the database
	EnumDocumentIDs(ctx context.Context, callback func(context.Context, uu.ID) error) error

	// EnumCompanyDocumentIDs calls the passed callback with the ID of every document of a company in the database
	EnumCompanyDocumentIDs(ctx context.Context, companyID uu.ID, callback func(context.Context, uu.ID) error) error

	// DocumentCompanyID returns the companyID for a docID
	DocumentCompanyID(ctx context.Context, docID uu.ID) (companyID uu.ID, err error)

	// SetDocumentCompanyID changes the companyID for a document
	SetDocumentCompanyID(ctx context.Context, docID, companyID uu.ID) error

	// DocumentVersions returns all version timestamps of a document in ascending order.
	// Returns nil and no error if the document does not exist or has no versions.
	DocumentVersions(ctx context.Context, docID uu.ID) ([]VersionTime, error)

	// LatestDocumentVersion returns the lates VersionTime of a document
	LatestDocumentVersion(ctx context.Context, docID uu.ID) (VersionTime, error)

	// DocumentVersionInfo returns the VersionInfo for a VersionTime
	DocumentVersionInfo(ctx context.Context, docID uu.ID, version VersionTime) (*VersionInfo, error)

	// LatestDocumentVersionInfo returns the VersionInfo for the latest document version
	LatestDocumentVersionInfo(ctx context.Context, docID uu.ID) (*VersionInfo, error)

	// DocumentVersionFileProvider returns a FileProvider for the files of a document version
	DocumentVersionFileProvider(ctx context.Context, docID uu.ID, version VersionTime) (FileProvider, error)

	// ReadDocumentVersionFile returns the contents of a file of a document version.
	// Wrapped ErrDocumentNotFound, ErrDocumentVersionNotFound, ErrDocumentFileNotFound
	// will be returned in case of such error conditions.
	ReadDocumentVersionFile(ctx context.Context, docID uu.ID, version VersionTime, filename string) (data []byte, err error)

	// DeleteDocument deletes all versions of a document
	// including its workspace directory if checked out.
	DeleteDocument(ctx context.Context, docID uu.ID) error

	// DeleteDocumentVersion deletes a version of a document that must not be checked out
	// and returns the left over versions.
	// If the version is the only version of the document,
	// then the document will be deleted and no leftVersions are returned.
	// Returns wrapped ErrDocumentNotFound, ErrDocumentVersionNotFound, ErrDocumentCheckedOut
	// in case of such error conditions.
	// DeleteDocumentVersion should not be used for normal docdb operations,
	// just to clean up mistakes or sync database states.
	DeleteDocumentVersion(ctx context.Context, docID uu.ID, version VersionTime) (leftVersions []VersionTime, err error)

	CreateDocument(ctx context.Context, companyID, docID, userID uu.ID, reason string, files []fs.FileReader) (*VersionInfo, error)

	AddDocumentVersion(ctx context.Context, docID, userID uu.ID, reason string, createVersion CreateVersionFunc, onNewVersion OnNewVersionFunc) error

	// RestoreDocument
	RestoreDocument(ctx context.Context, doc *HashedDocument, merge bool) error
}

Conn is an interface for a docdb connection.

func GetConn

func GetConn() Conn

GetConn returns the configured database connection

func NewConnWithError

func NewConnWithError(err error) Conn

NewConnWithError returns a Conn where all methods return the passed error.

type CreateVersionFunc

type CreateVersionFunc func(ctx context.Context, prevVersion VersionTime, prevFiles FileProvider) (writeFiles []fs.FileReader, removeFiles []string, newCompanyID *uu.ID, err error)

type DeprecatedConn

type DeprecatedConn interface {
	Conn

	// DocumentCheckOutStatus returns the CheckOutStatus of a document.
	// If the document is not checked out, then a nil CheckOutStatus will be returned.
	// The methods Valid() and String() can be called on a nil CheckOutStatus.
	// ErrDocumentNotFound is returned if the document does not exist.
	DocumentCheckOutStatus(ctx context.Context, docID uu.ID) (*CheckOutStatus, error)

	// CheckedOutDocuments returns the CheckOutStatus of all checked out documents.
	CheckedOutDocuments(ctx context.Context) ([]*CheckOutStatus, error)

	// CheckOutNewDocument creates a new document for a company in checked out state.
	CheckOutNewDocument(ctx context.Context, docID, companyID, userID uu.ID, reason string) (status *CheckOutStatus, err error)

	// CheckOutDocument checks out a document for a user with a stated reason.
	// Returns ErrDocumentCheckedOut if the document is already checked out.
	CheckOutDocument(ctx context.Context, docID, userID uu.ID, reason string) (*CheckOutStatus, error)

	// CancelCheckOutDocument cancels a potential checkout.
	// No error is returned if the document was not checked out.
	// If the checkout was created by CheckOutNewDocument,
	// then the new document is deleted without leaving any history
	// and the returned lastVersion.IsNull() is true.
	CancelCheckOutDocument(ctx context.Context, docID uu.ID) (wasCheckedOut bool, lastVersion VersionTime, err error)

	// CheckInDocument checks in a checked out document
	// and returns the VersionInfo for the newly created version.
	CheckInDocument(ctx context.Context, docID uu.ID) (*VersionInfo, error)

	// CheckedOutDocumentDir returns a fs.File for the directory
	// where a document would be checked out.
	CheckedOutDocumentDir(docID uu.ID) fs.File
}

DeprecatedConn has check-out, check-in and checkout directory methods. It is deprecated and will be removed in the future. Use the Conn interface instead.

type ErrDocumentAlreadyExists

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

func NewErrDocumentAlreadyExists

func NewErrDocumentAlreadyExists(docID uu.ID) ErrDocumentAlreadyExists

func (ErrDocumentAlreadyExists) Error

func (e ErrDocumentAlreadyExists) Error() string

type ErrDocumentChanged

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

func NewErrDocumentChanged

func NewErrDocumentChanged(docID uu.ID, version VersionTime) ErrDocumentChanged

func (ErrDocumentChanged) Error

func (e ErrDocumentChanged) Error() string

type ErrDocumentCheckedOut

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

func NewErrDocumentCheckedOut

func NewErrDocumentCheckedOut(status *CheckOutStatus) ErrDocumentCheckedOut

func (ErrDocumentCheckedOut) CheckOutReason

func (e ErrDocumentCheckedOut) CheckOutReason() string

func (ErrDocumentCheckedOut) CheckOutUserID

func (e ErrDocumentCheckedOut) CheckOutUserID() uu.ID

func (ErrDocumentCheckedOut) Error

func (e ErrDocumentCheckedOut) Error() string

type ErrDocumentFileNotFound

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

func NewErrDocumentFileNotFound

func NewErrDocumentFileNotFound(docID uu.ID, filename string) ErrDocumentFileNotFound

func (ErrDocumentFileNotFound) DocID

func (e ErrDocumentFileNotFound) DocID() uu.ID

func (ErrDocumentFileNotFound) Error

func (e ErrDocumentFileNotFound) Error() string

func (ErrDocumentFileNotFound) Filename

func (e ErrDocumentFileNotFound) Filename() string

func (ErrDocumentFileNotFound) Is

func (ErrDocumentFileNotFound) Is(target error) bool

type ErrDocumentHasNoCommitedVersion

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

func NewErrDocumentHasNoCommitedVersion

func NewErrDocumentHasNoCommitedVersion(docID uu.ID) ErrDocumentHasNoCommitedVersion

func (ErrDocumentHasNoCommitedVersion) Error

type ErrDocumentNotCheckedOut

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

func NewErrDocumentNotCheckedOut

func NewErrDocumentNotCheckedOut(docID uu.ID) ErrDocumentNotCheckedOut

func (ErrDocumentNotCheckedOut) Error

func (e ErrDocumentNotCheckedOut) Error() string

type ErrDocumentNotFound

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

func NewErrDocumentNotFound

func NewErrDocumentNotFound(docID uu.ID) ErrDocumentNotFound

func (ErrDocumentNotFound) DocID

func (e ErrDocumentNotFound) DocID() uu.ID

func (ErrDocumentNotFound) Error

func (e ErrDocumentNotFound) Error() string

func (ErrDocumentNotFound) Is

func (ErrDocumentNotFound) Is(target error) bool

type ErrDocumentVersionNotFound

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

func NewErrDocumentVersionNotFound

func NewErrDocumentVersionNotFound(docID uu.ID, version VersionTime) ErrDocumentVersionNotFound

func (ErrDocumentVersionNotFound) DocID

func (e ErrDocumentVersionNotFound) DocID() uu.ID

func (ErrDocumentVersionNotFound) Error

func (ErrDocumentVersionNotFound) Is

func (ErrDocumentVersionNotFound) Version

type ErrVersionAlreadyExists

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

func NewErrVersionAlreadyExists

func NewErrVersionAlreadyExists(docID uu.ID, version VersionTime) ErrVersionAlreadyExists

func (ErrVersionAlreadyExists) Error

func (e ErrVersionAlreadyExists) Error() string

type FileInfo

type FileInfo struct {
	Name string
	Size int64
	Hash string
}

func ReadFileInfo

func ReadFileInfo(ctx context.Context, file fs.FileReader) (info FileInfo, err error)

ReadFileInfo reads the file content from file and returns a FileInfo with the file name, size and hash.

type FileProvider

type FileProvider interface {
	HasFile(filename string) (bool, error)
	ListFiles(ctx context.Context) (filenames []string, err error)
	ReadFile(ctx context.Context, filename string) ([]byte, error)
}

FileProvider is an interface for read access to named files

func CheckedOutDocumentFileProvider

func CheckedOutDocumentFileProvider(docID uu.ID) (p FileProvider, err error)

CheckedOutDocumentFileProvider returns a FileProvider for the directory where a document would be checked out.

func DirFileProvider

func DirFileProvider(dir fs.File) FileProvider

DirFileProvider returns a FileProvider for a fs.File directory

func DocumentVersionFileProvider

func DocumentVersionFileProvider(ctx context.Context, docID uu.ID, version VersionTime) (p FileProvider, err error)

DocumentVersionFileProvider returns a FileProvider for the files of a document version

func ExtFileProvider

func ExtFileProvider(base FileProvider, extFiles ...fs.FileReader) FileProvider

ExtFileProvider returns a FileProvider that extends a base FileProvider with additional files that will be returned before the files of the base FileProvider.

func LatestDocumentVersionFileProvider

func LatestDocumentVersionFileProvider(ctx context.Context, docID uu.ID) (p FileProvider, err error)

func RemoveFileProvider

func RemoveFileProvider(base FileProvider, removeFilenames ...string) FileProvider

RemoveFileProvider returns a FileProvider that wraps a base FileProvider and does not return files with the passed removeFilenames.

type HashedDocument

type HashedDocument struct {
	ID          uu.ID
	CompanyID   uu.ID
	HashedFiles map[string][]byte
	Versions    map[VersionTime]*HashedVersion
}

func ReadHashedDocument

func ReadHashedDocument(ctx context.Context, conn Conn, docID uu.ID) (doc *HashedDocument, err error)

func (*HashedDocument) VersionInfo

func (doc *HashedDocument) VersionInfo(versionTime VersionTime) *VersionInfo

func (*HashedDocument) VersionTimes

func (doc *HashedDocument) VersionTimes() []VersionTime

type HashedVersion

type HashedVersion struct {
	CommitUserID uu.ID
	CommitReason string
	FileHashes   map[string]string // filename -> hash
}

type MockFileProvider

type MockFileProvider struct {
	HasFileMock   func(filename string) (bool, error)
	ListFilesMock func(ctx context.Context) (filenames []string, err error)
	ReadFileMock  func(ctx context.Context, filename string) ([]byte, error)
}

func (*MockFileProvider) HasFile

func (fp *MockFileProvider) HasFile(filename string) (bool, error)

func (*MockFileProvider) ListFiles

func (fp *MockFileProvider) ListFiles(ctx context.Context) (filenames []string, err error)

func (*MockFileProvider) ReadFile

func (fp *MockFileProvider) ReadFile(ctx context.Context, filename string) ([]byte, error)

type OnNewVersionFunc

type OnNewVersionFunc func(ctx context.Context, versionInfo *VersionInfo) error

type VersionInfo

type VersionInfo struct {
	CompanyID    uu.ID
	DocID        uu.ID
	Version      VersionTime
	PrevVersion  VersionTime
	CommitUserID uu.ID
	CommitReason string

	Files         map[string]FileInfo
	AddedFiles    []string
	RemovedFiles  []string
	ModifiedFiles []string
}

func CheckInDocument

func CheckInDocument(ctx context.Context, docID uu.ID) (v *VersionInfo, err error)

CheckInDocument checks in a checked out document and returns the VersionInfo for the newly created version.

func CreateDocument

func CreateDocument(ctx context.Context, companyID, docID, userID uu.ID, reason string, files []fs.FileReader) (versionInfo *VersionInfo, err error)

func DocumentFileReader

func DocumentFileReader(ctx context.Context, docID uu.ID, filename string) (fileReader fs.FileReader, versionInfo *VersionInfo, err error)

DocumentFileReader returns a fs.FileReader for a file of the latest document version. Wrapped ErrDocumentNotFound, ErrDocumentHasNoCommitedVersion, ErrDocumentFileNotFound will be returned in case of such error conditions.

func DocumentVersionInfo

func DocumentVersionInfo(ctx context.Context, docID uu.ID, version VersionTime) (info *VersionInfo, err error)

DocumentVersionInfo returns the VersionInfo for a VersionTime

func LatestDocumentVersionInfo

func LatestDocumentVersionInfo(ctx context.Context, docID uu.ID) (info *VersionInfo, err error)

LatestDocumentVersionInfo returns the VersionInfo for the latest document version

func NewVersionInfo

func NewVersionInfo(companyID, docID uu.ID, version, prevVersion VersionTime, commitUserID uu.ID, commitReason string, versionDir, prevVersionDir fs.File, ignoreFiles ...string) (versionInfo *VersionInfo, err error)

NewVersionInfo uses the files from versionDir. When prevVersionDir is "" then all files are added to the AddedFiles slice, else the according diff slices RemovedFiles and ModidfiedFiles will also be filled. Files in versionDir and prevVersionDir with names from ignoreFiles will be ignored. The versionInfo file slices will be sorted.

func ReadDocumentFile

func ReadDocumentFile(ctx context.Context, docID uu.ID, filename string) (data []byte, versionInfo *VersionInfo, err error)

ReadDocumentFile reads a file of the latest document version

func ReadVersionInfoJSON

func ReadVersionInfoJSON(file fs.File, writeFixedVersion bool) (versionInfo *VersionInfo, err error)

func (*VersionInfo) EqualFiles

func (vi *VersionInfo) EqualFiles(other *VersionInfo) bool

func (*VersionInfo) String

func (vi *VersionInfo) String() string

func (*VersionInfo) WriteJSON

func (vi *VersionInfo) WriteJSON(file fs.File) error

type VersionTime

type VersionTime struct {
	Time time.Time
}

VersionTime of a document. VersionTime implements the database/sql.Scanner and database/sql/driver.Valuer interfaces and will treat a zero VersionTime value as SQL NULL value.

func CancelCheckOutDocument

func CancelCheckOutDocument(ctx context.Context, docID uu.ID) (wasCheckedOut bool, lastVersion VersionTime, err error)

CancelCheckOutDocument cancels a potential checkout. No error is returned if the document was not checked out. If the checkout was created by CheckOutNewDocument, then the new document is deleted without leaving any history and the returned lastVersion.IsNull() is true.

func DeleteDocumentVersion

func DeleteDocumentVersion(ctx context.Context, docID uu.ID, version VersionTime) (leftVersions []VersionTime, err error)

DeleteDocumentVersion deletes a version of a document that must not be checked out and returns the left over versions. If the version is the only version of the document, then the document will be deleted and no leftVersions are returned. Returns wrapped ErrDocumentNotFound, ErrDocumentVersionNotFound, ErrDocumentCheckedOut in case of such error conditions. DeleteDocumentVersion should not be used for normal docdb operations, just to clean up mistakes or sync database states.

func DocumentVersions

func DocumentVersions(ctx context.Context, docID uu.ID) (versions []VersionTime, err error)

DocumentVersions returns all version timestamps of a document in ascending order. Returns nil and no error if the document does not exist or has no versions.

func LatestDocumentVersion

func LatestDocumentVersion(ctx context.Context, docID uu.ID) (version VersionTime, err error)

LatestDocumentVersion returns the lates VersionTime of a document

func MustVersionTimeFromString

func MustVersionTimeFromString(str string) VersionTime

MustVersionTimeFromString parses a string as VersionTime. The strings "", "null", "NULL" will be parsed as null VersionTime. Any error causes a panic.

func NewVersionTime

func NewVersionTime(ctx context.Context) VersionTime

NewVersionTime returns the timestamp for a new version. If the passed context was created with ContextWithVersionTime then the version from the context is returned else the current time.

func PostgresGetLatestDocumentVersionTimeAndID

func PostgresGetLatestDocumentVersionTimeAndID(ctx context.Context, documentID uu.ID) (version VersionTime, id uu.ID, err error)

func PostgresGetLatestVersion

func PostgresGetLatestVersion(ctx context.Context, documentID uu.ID) (version VersionTime, err error)

func ReadLatestDocumentVersionFile

func ReadLatestDocumentVersionFile(ctx context.Context, docID uu.ID, filename string) (data []byte, version VersionTime, err error)

func SubstituteDeletedDocumentVersion

func SubstituteDeletedDocumentVersion(ctx context.Context, docID uu.ID, version VersionTime) (validVersion VersionTime, err error)

SubstituteDeletedDocumentVersion will substitue the passed version with the next existing version it does not exist anymore. Will return ErrDocumentHasNoCommitedVersion if there is no other commited version for the document.

func VersionTimeFrom

func VersionTimeFrom(t time.Time) VersionTime

VersionTimeFrom returns a VersionTime for the given time translated to UTC and truncated to milliseconds

func VersionTimeFromString

func VersionTimeFromString(str string) (VersionTime, error)

VersionTimeFromString parses a string as VersionTime. The strings "", "null", "NULL" will be parsed as null VersionTime.

func (VersionTime) After

func (v VersionTime) After(other VersionTime) bool

func (VersionTime) Before

func (v VersionTime) Before(other VersionTime) bool

func (VersionTime) Compare

func (v VersionTime) Compare(r VersionTime) int

Compare compares the time instant v.Time with r.Time. If v is before r, it returns -1; if v is after r, it returns +1; if they're the same, it returns 0.

func (VersionTime) Equal

func (v VersionTime) Equal(other VersionTime) bool

func (VersionTime) IsNotNull

func (v VersionTime) IsNotNull() bool

func (VersionTime) IsNull

func (v VersionTime) IsNull() bool

func (VersionTime) MarshalText

func (v VersionTime) MarshalText() (text []byte, err error)

MarshalText implements the encoding.TextMarshaler interface

func (VersionTime) NullableTime

func (v VersionTime) NullableTime() nullable.Time

NullableTime returns the version time as nullable.Time

func (VersionTime) PrettyPrint

func (v VersionTime) PrettyPrint(w io.Writer)

PrettyPrint implements the pretty.Printable interface

func (*VersionTime) Scan

func (v *VersionTime) Scan(value any) error

Scan implements the database/sql.Scanner interface.

func (*VersionTime) SetNull

func (v *VersionTime) SetNull()

func (VersionTime) String

func (v VersionTime) String() string

String implements the fmt.Stringer interface.

func (*VersionTime) UnmarshalText

func (v *VersionTime) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface

func (VersionTime) Value

func (v VersionTime) Value() (sqldriver.Value, error)

Value implements the driver database/sql/driver.Valuer interface.

Directories

Path Synopsis
hashdb module

Jump to

Keyboard shortcuts

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