hashdb

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: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultSQLQueries = SQLQueries{
	DocumentExists: `select exists(select from public.document where id = $1)`,

	AllDocumentIDs:     `select id from public.document`,
	CompanyDocumentIDs: `select id from public.document where client_company_id = $1`,
	DocumentCompanyID:  `select client_company_id from public.document where id = $1`,
	SetDocumentCompanyID: `
		update public.document
		set client_company_id=$2, updated_at=now()
		where id = $1 and client_company_id <> $2
		returning true`,
	DocumentVersions: `select array_agg(version order by version) from docdb.document_version where document_id = $1`,
	DocumentVersionInfo: `
		select
			prev_version, 
			commit_user_id,
			commit_reason,
			added_files,
			removed_files,
			modified_files
		from docdb.document_version
		where document_id = $1 and version = $2`,
	LatestDocumentVersionInfo: `
		select
			version,
			prev_version, 
			commit_user_id,
			commit_reason,
			added_files,
			removed_files,
			modified_files
		from docdb.document_version
		where document_id = $1
		order by version desc
		limit 1`,
	LatestDocumentVersion: `select version from docdb.document_version where document_id = $1 order by version desc limit 1`,
	DocumentVersionFileHash: `
		select f.hash
		from docdb.document_version as v
		inner join docdb.document_version_file as f
			on f.document_version_id = v.id and f.name = $3
		where v.document_id = $1 and v.version = $2`,
}

Functions

This section is empty.

Types

type Conn

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

func NewConn

func NewConn(queries *SQLQueries, files FileStore) *Conn

func (*Conn) AddDocumentVersion

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

func (*Conn) CancelCheckOutDocument

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

func (*Conn) CheckInDocument

func (c *Conn) CheckInDocument(ctx context.Context, docID uu.ID) (versionInfo *docdb.VersionInfo, err error)

func (*Conn) CheckOutDocument

func (c *Conn) CheckOutDocument(ctx context.Context, docID, userID uu.ID, reason string) (checkOutStatus *docdb.CheckOutStatus, err error)

func (*Conn) CheckOutNewDocument

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

func (*Conn) CheckedOutDocumentDir

func (c *Conn) CheckedOutDocumentDir(docID uu.ID) fs.File

func (*Conn) CheckedOutDocuments

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

func (*Conn) CreateDocument

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

func (*Conn) DeleteDocument

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

func (*Conn) DeleteDocumentVersion

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

func (*Conn) DocumentCheckOutStatus

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

func (*Conn) DocumentCompanyID

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

func (*Conn) DocumentExists

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

func (*Conn) DocumentVersionFileProvider

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

func (*Conn) DocumentVersionInfo

func (c *Conn) DocumentVersionInfo(ctx context.Context, docID uu.ID, version docdb.VersionTime) (versionInfo *docdb.VersionInfo, err error)

func (*Conn) DocumentVersions

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

func (*Conn) EnumCompanyDocumentIDs

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

func (*Conn) EnumDocumentIDs

func (c *Conn) EnumDocumentIDs(ctx context.Context, callback func(context.Context, uu.ID) error) error

func (*Conn) LatestDocumentVersion

func (c *Conn) LatestDocumentVersion(ctx context.Context, docID uu.ID) (latest docdb.VersionTime, err error)

func (*Conn) LatestDocumentVersionInfo

func (c *Conn) LatestDocumentVersionInfo(ctx context.Context, docID uu.ID) (versionInfo *docdb.VersionInfo, err error)

func (*Conn) ReadDocumentVersionFile

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

func (*Conn) RestoreDocument

func (c *Conn) RestoreDocument(ctx context.Context, doc *docdb.HashedDocument, merge bool) error

func (*Conn) SetDocumentCompanyID

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

func (*Conn) String

func (c *Conn) String() string

type FileStore

type FileStore interface {
	fmt.Stringer

	Create(ctx context.Context, data []byte) (hash string, err error)
	Delete(ctx context.Context, hash string) error
	Read(ctx context.Context, hash string) ([]byte, error)
}

func NewLocalFileStore

func NewLocalFileStore(baseDir fs.File, hashFunc HashFunc) (FileStore, error)

func NewS3FileStore

func NewS3FileStore(ctx context.Context, bucketName string, hashFunc HashFunc) (FileStore, error)

type HashFunc

type HashFunc func(data []byte) (hash string)

type SQLQueries

type SQLQueries struct {
	// Args: (docID uu.ID) => bool
	DocumentExists string
	InsertDocument string
	// Args: () => uu.ID rows
	AllDocumentIDs string
	// Args: (companyID uu.ID) => uu.ID rows
	CompanyDocumentIDs string
	// Args: (docID uu.ID) => uu.ID
	DocumentCompanyID string
	// Args: (docID, companyID uu.ID) => true if updated
	SetDocumentCompanyID string
	// Args: (docID uu.ID) => []docdb.VersionTime
	DocumentVersions string
	// Args: (docID uu.ID, version docdb.VersionTime) => (...todo...)
	DocumentVersionInfo       string
	LatestDocumentVersionInfo string
	LatestDocumentVersion     string
	DocumentVersionFileHash   string
}

Jump to

Keyboard shortcuts

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