database

package
v3.0.0-...-1148c22 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2025 License: Apache-2.0 Imports: 22 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            Type           `toml:"type"`
	Debug           bool           `toml:"debug"`
	ExpireAfter     timex.Duration `toml:"expire_after"`
	CleanupInterval timex.Duration `toml:"cleanup_interval"`

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

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

func (Config) PostgresDataSourceName

func (c Config) PostgresDataSourceName() string

func (Config) String

func (c Config) String() string

type DB

type DB interface {
	gomigrate.Queryer

	GetDocument(ctx context.Context, documentID string) ([]File, error)
	GetDocumentVersion(ctx context.Context, documentID string, documentVersion int64) ([]File, error)
	GetVersionCount(ctx context.Context, documentID string) (int, error)
	GetDocumentVersions(ctx context.Context, documentID string) ([]int64, error)
	GetDocumentVersionsWithFiles(ctx context.Context, documentID string, withContent bool) (map[int64][]File, error)
	CreateDocument(ctx context.Context, files []File) (*string, *int64, error)
	UpdateDocument(ctx context.Context, documentID string, files []File) (*int64, error)
	DeleteDocument(ctx context.Context, documentID string) (*Document, error)
	DeleteDocumentVersion(ctx context.Context, documentID string, documentVersion int64) (*Document, error)
	DeleteDocumentVersions(ctx context.Context, documentID string) error
	DeleteExpiredDocuments(ctx context.Context, expireAfter time.Duration) ([]Document, error)

	GetDocumentFile(ctx context.Context, documentID string, fileName string) (*File, error)
	GetDocumentFileVersion(ctx context.Context, documentID string, documentVersion int64, fileName string) (*File, error)
	DeleteDocumentFile(ctx context.Context, documentID string, fileName string) error
	DeleteDocumentVersionFile(ctx context.Context, documentID string, documentVersion int64, fileName string) error

	GetWebhook(ctx context.Context, documentID string, webhookID string, secret string) (*Webhook, error)
	GetWebhooksByDocumentID(ctx context.Context, documentID string) ([]Webhook, error)
	GetAndDeleteWebhooksByDocumentID(ctx context.Context, documentID string) ([]Webhook, error)
	CreateWebhook(ctx context.Context, documentID string, url string, secret string, events []string) (*Webhook, error)
	UpdateWebhook(ctx context.Context, documentID string, webhookID string, secret string, newURL string, newSecret string, newEvents []string) (*Webhook, error)
	DeleteWebhook(ctx context.Context, documentID string, webhookID string, secret string) error

	Close() error
}

func New

func New(ctx context.Context, cfg Config, migrations fs.FS) (DB, 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"`
	ExpiresAt       *time.Time `db:"expires_at"`
	OrderIndex      int        `db:"order_index"`
}

type Type

type Type string
const (
	TypePostgres Type = "postgres"
	TypeSQLite   Type = "sqlite"
)

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