dalgo2ghingitdb

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package dalgo2ghingitdb provides a DALgo database adapter for reading inGitDB repositories from GitHub using the GitHub API. It supports read-only access to public repositories with no authentication required. Future versions will support authentication and write operations for private repositories.

Index

Constants

View Source
const DatabaseID = "ingitdb-github"

Variables

This section is empty.

Functions

func NewGitHubDB

func NewGitHubDB(cfg Config) (dal.DB, error)

NewGitHubDB creates a GitHub repository adapter. Note: Definition is required for most operations, so prefer NewGitHubDBWithDef.

func NewGitHubDBWithDef

func NewGitHubDBWithDef(cfg Config, def *ingitdb.Definition) (dal.DB, error)

Types

type BatchingGitHubDB added in v1.2.0

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

BatchingGitHubDB wraps a githubDB so that RunReadwriteTransaction buffers every tx.Set / tx.Insert / tx.Delete call inside the worker, then emits exactly one commit via the Git Data API when the worker returns nil.

Reads (Get, RunReadonlyTransaction, ExecuteQuery*) delegate to the underlying githubDB unchanged — they read the pre-tx state from remote and do not observe buffered writes (set-mode callers fetch matches in a separate read-only pass before opening the write tx, so this limitation does not affect them).

Use this in place of the per-file github DB when an operation may touch multiple records — `update --from --where`, `delete --from --where`, `update --from --all`, `delete --from --all`. Single-record operations already produce one commit through the Contents API and should keep using the plain githubDB.

func NewBatchingGitHubDB added in v1.2.0

func NewBatchingGitHubDB(cfg Config, def *ingitdb.Definition, commitMessage string) (*BatchingGitHubDB, error)

NewBatchingGitHubDB builds a BatchingGitHubDB for the given Config + def. commitMessage is the message used when flushing buffered changes; callers supply something human-readable like "ingitdb: update countries (batch)".

func (BatchingGitHubDB) Adapter added in v1.2.0

func (db BatchingGitHubDB) Adapter() dal.Adapter

func (BatchingGitHubDB) ExecuteQueryToRecordsReader added in v1.2.0

func (db BatchingGitHubDB) ExecuteQueryToRecordsReader(ctx context.Context, query dal.Query) (dal.RecordsReader, error)

func (BatchingGitHubDB) ExecuteQueryToRecordsetReader added in v1.2.0

func (db BatchingGitHubDB) ExecuteQueryToRecordsetReader(ctx context.Context, query dal.Query, options ...recordset.Option) (dal.RecordsetReader, error)

func (BatchingGitHubDB) Exists added in v1.2.0

func (db BatchingGitHubDB) Exists(ctx context.Context, key *dal.Key) (bool, error)

func (BatchingGitHubDB) Get added in v1.2.0

func (db BatchingGitHubDB) Get(ctx context.Context, record dal.Record) error

func (BatchingGitHubDB) GetMulti added in v1.2.0

func (db BatchingGitHubDB) GetMulti(ctx context.Context, records []dal.Record) error

func (BatchingGitHubDB) ID added in v1.2.0

func (db BatchingGitHubDB) ID() string

func (BatchingGitHubDB) RunReadonlyTransaction added in v1.2.0

func (db BatchingGitHubDB) RunReadonlyTransaction(ctx context.Context, f dal.ROTxWorker, options ...dal.TransactionOption) error

func (*BatchingGitHubDB) RunReadwriteTransaction added in v1.2.0

func (db *BatchingGitHubDB) RunReadwriteTransaction(ctx context.Context, f dal.RWTxWorker, options ...dal.TransactionOption) error

RunReadwriteTransaction overrides githubDB.RunReadwriteTransaction with a batching variant. Every Set / Insert / Delete inside f is buffered; when f returns nil, all buffered changes are flushed to GitHub as one commit. If f returns an error, no changes are committed (the remote is untouched).

func (BatchingGitHubDB) Schema added in v1.2.0

func (db BatchingGitHubDB) Schema() dal.Schema

type Config

type Config struct {
	Owner      string
	Repo       string
	Ref        string
	Token      string
	APIBaseURL string
	HTTPClient *http.Client
}

Config defines connection settings for reading an inGitDB repository from GitHub.

type FileReader

type FileReader interface {
	ReadFile(ctx context.Context, path string) (content []byte, found bool, err error)
	ListDirectory(ctx context.Context, dirPath string) (entries []string, err error)
}

FileReader reads repository files by path from GitHub.

func NewGitHubFileReader

func NewGitHubFileReader(cfg Config) (FileReader, error)

type TreeChange added in v1.1.0

type TreeChange struct {
	Path    string
	Content []byte
}

TreeChange describes a single path modification within a tree. Content nil means "delete the file at Path"; non-nil Content means "set the file at Path to this content" (creating it if absent).

type TreeWriter added in v1.1.0

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

TreeWriter performs atomic multi-file commits on a remote GitHub repository via the Git Data API (blobs / trees / commits / refs). Unlike the per-file Contents API used by FileReader.writeFile / deleteFile (which each produce their own commit), TreeWriter bundles arbitrary file modifications into a single commit — satisfying spec REQ:one-commit-per-write for multi-file operations such as `drop collection`.

func NewTreeWriter added in v1.1.0

func NewTreeWriter(cfg Config) (*TreeWriter, error)

NewTreeWriter builds a TreeWriter for the given Config. It does not perform any network I/O; the first request fires on the first method call.

func (*TreeWriter) CommitChanges added in v1.1.0

func (w *TreeWriter) CommitChanges(ctx context.Context, message string, changes []TreeChange) (string, error)

CommitChanges atomically applies the given changes in a single commit on the target branch and returns the new commit SHA. The repository ends in exactly one of two states: either every change is applied as part of the new commit, or no change is applied at all (the previous head is unchanged).

Changes with nil Content delete the path; non-nil Content creates or updates a blob at the path with that content. Mode is set to "100644" (non-executable file) for all non-delete entries.

func (*TreeWriter) ListFilesUnder added in v1.1.0

func (w *TreeWriter) ListFilesUnder(ctx context.Context, dir string) ([]string, error)

ListFilesUnder returns the paths of every blob in the current tree of the target branch whose path equals dir or has dir+"/" as a prefix. Empty dir returns every blob in the tree. Returned paths are relative to the repo root. Used to enumerate the files to delete when dropping a collection.

Errors if the upstream tree is truncated (too large to fetch in one call); drop semantics require an atomic view of the directory.

Jump to

Keyboard shortcuts

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