database

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Type            string        `cfg:"type"`
	Debug           bool          `cfg:"debug"`
	ExpireAfter     time.Duration `cfg:"expire_after"`
	CleanupInterval time.Duration `cfg:"cleanup_interval"`

	// SQLite
	Path string `cfg:"path"`

	// PostgreSQL
	Host     string `cfg:"host"`
	Port     int    `cfg:"port"`
	Username string `cfg:"username"`
	Password string `cfg:"password"`
	Database string `cfg:"database"`
	SSLMode  string `cfg:"ssl_mode"`
}

func (Config) PostgresDataSourceName

func (c Config) PostgresDataSourceName() string

func (Config) String

func (c Config) String() string

type DB

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

func New

func New(ctx context.Context, cfg Config, schema string) (*DB, error)

func (*DB) Close

func (d *DB) Close() error

func (*DB) CreateDocument

func (d *DB) CreateDocument(ctx context.Context, files []File) (*string, *int64, error)

func (*DB) CreateWebhook

func (d *DB) CreateWebhook(ctx context.Context, documentID string, url string, secret string, events []string) (*Webhook, error)

func (*DB) DeleteDocument

func (d *DB) DeleteDocument(ctx context.Context, documentID string) (*Document, error)

func (*DB) DeleteDocumentFile

func (d *DB) DeleteDocumentFile(ctx context.Context, documentID string, fileName string) error

func (*DB) DeleteDocumentVersion

func (d *DB) DeleteDocumentVersion(ctx context.Context, documentID string, documentVersion int64) (*Document, error)

func (*DB) DeleteDocumentVersionFile

func (d *DB) DeleteDocumentVersionFile(ctx context.Context, documentID string, documentVersion int64, fileName string) error

func (*DB) DeleteDocumentVersions

func (d *DB) DeleteDocumentVersions(ctx context.Context, documentID string) error

func (*DB) DeleteExpiredDocuments

func (d *DB) DeleteExpiredDocuments(ctx context.Context, expireAfter time.Duration) error

func (*DB) DeleteWebhook

func (d *DB) DeleteWebhook(ctx context.Context, documentID string, webhookID string, secret string) error

func (*DB) GetAndDeleteWebhooksByDocumentID

func (d *DB) GetAndDeleteWebhooksByDocumentID(ctx context.Context, documentID string) ([]Webhook, error)

func (*DB) GetDocument

func (d *DB) GetDocument(ctx context.Context, documentID string) ([]File, error)

func (*DB) GetDocumentFile

func (d *DB) GetDocumentFile(ctx context.Context, documentID string, fileName string) (*File, error)

func (*DB) GetDocumentFileVersion

func (d *DB) GetDocumentFileVersion(ctx context.Context, documentID string, documentVersion int64, fileName string) (*File, error)

func (*DB) GetDocumentVersion

func (d *DB) GetDocumentVersion(ctx context.Context, documentID string, documentVersion int64) ([]File, error)

func (*DB) GetDocumentVersions

func (d *DB) GetDocumentVersions(ctx context.Context, documentID string) ([]int64, error)

func (*DB) GetDocumentVersionsWithFiles

func (d *DB) GetDocumentVersionsWithFiles(ctx context.Context, documentID string, withContent bool) (map[int64][]File, error)

func (*DB) GetVersionCount

func (d *DB) GetVersionCount(ctx context.Context, documentID string) (int, error)

func (*DB) GetWebhook

func (d *DB) GetWebhook(ctx context.Context, documentID string, webhookID string, secret string) (*Webhook, error)

func (*DB) GetWebhooksByDocumentID

func (d *DB) GetWebhooksByDocumentID(ctx context.Context, documentID string) ([]Webhook, error)

func (*DB) UpdateDocument

func (d *DB) UpdateDocument(ctx context.Context, documentID string, files []File) (*int64, error)

func (*DB) UpdateWebhook

func (d *DB) UpdateWebhook(ctx context.Context, documentID string, webhookID string, secret string, newURL string, newSecret string, newEvents []string) (*Webhook, error)

type Document

type Document struct {
	ID      string
	Version int64
	Files   []File
}

type File

type File struct {
	DocumentID      string `db:"document_id"`
	DocumentVersion int64  `db:"document_version"`
	Name            string `db:"name"`
	Content         string `db:"content"`
	Language        string `db:"language"`
}

type Webhook

type Webhook struct {
	ID         string `db:"id"`
	DocumentID string `db:"document_id"`
	URL        string `db:"url"`
	Secret     string `db:"secret"`
	Events     string `db:"events"`
}

type WebhookUpdate

type WebhookUpdate struct {
	ID         string `db:"id"`
	DocumentID string `db:"document_id"`
	Secret     string `db:"secret"`

	NewURL    string `db:"new_url"`
	NewSecret string `db:"new_secret"`
	NewEvents string `db:"new_events"`
}

Jump to

Keyboard shortcuts

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