sqlrepo

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2025 License: Apache-2.0, MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MigrationsFS embed.FS
View Source
var Schema string

Functions

func Null

func Null[T any](v *T) sql.Null[T]

func NullString

func NullString(s *string) sql.NullString

Types

type FileInfo

type FileInfo struct {
	Path string
	Size uint64
}

type Repo

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

func New

func New(db *sql.DB) *Repo

New creates a new Repo instance with the given database connection.

func (*Repo) AddNodeToShard

func (r *Repo) AddNodeToShard(ctx context.Context, shardID id.ShardID, nodeCID cid.Cid, spaceDID did.DID, offset uint64, options ...shards.AddNodeToShardOption) error

AddNodeToShard adds a node to a shard in the repository. Note: the [offset] is NOT the absolute offset within the shard, but the offset into the *new* bytes in the shard CAR where the node data begins--in other words, the length of the length varint + the length of the CID bytes. The node's block will be indexed as appearing at `shard.size + offset`, running for `node.size` bytes, and then the shard size will be increased by `offset + node.size`.

func (*Repo) AddSourceToSpace

func (r *Repo) AddSourceToSpace(ctx context.Context, spaceDID did.DID, sourceID id.SourceID) error

AddSourceToSpace adds a source to a space in the repository.

func (*Repo) CIDForFSEntry

func (r *Repo) CIDForFSEntry(ctx context.Context, fsEntryID id.FSEntryID) (cid.Cid, error)

func (*Repo) Close

func (r *Repo) Close() error

func (*Repo) CompleteDAGScansForUpload

func (r *Repo) CompleteDAGScansForUpload(ctx context.Context, uploadID id.UploadID) ([]model.DAGScan, error)

func (*Repo) CreateDAGScan

func (r *Repo) CreateDAGScan(ctx context.Context, fsEntryID id.FSEntryID, isDirectory bool, uploadID id.UploadID, spaceDID did.DID) (dagmodel.DAGScan, error)

func (*Repo) CreateDirectoryChildren

func (r *Repo) CreateDirectoryChildren(ctx context.Context, parent *scanmodel.Directory, children []scanmodel.FSEntry) error

CreateDirectoryChildren links a directory to its children in the repository.

func (r *Repo) CreateLinks(ctx context.Context, parent cid.Cid, spaceDID did.DID, linkParams []model.LinkParams) error

CreateLinks creates links in the repository for the given parent CID and link parameters.

func (*Repo) CreateShard

func (r *Repo) CreateShard(ctx context.Context, uploadID id.UploadID, size uint64, digestState, pieceCidState []byte) (*model.Shard, error)

func (*Repo) CreateSource

func (r *Repo) CreateSource(ctx context.Context, name string, path string, options ...sourcemodel.SourceOption) (*sourcemodel.Source, error)

CreateSource creates a new source in the repository with the given name, path, and options.

func (*Repo) DeleteFSEntry

func (r *Repo) DeleteFSEntry(ctx context.Context, spaceDID did.DID, fsEntryID id.FSEntryID) error

func (*Repo) DeleteNodes

func (r *Repo) DeleteNodes(ctx context.Context, spaceDID did.DID, nodeCIDs []cid.Cid) error

func (*Repo) DeleteShard

func (r *Repo) DeleteShard(ctx context.Context, shardID id.ShardID) error

func (*Repo) DeleteSpace

func (r *Repo) DeleteSpace(ctx context.Context, spaceDID did.DID) error

DeleteSpace deletes a space from the repository.

func (*Repo) DirectoryChildren

func (r *Repo) DirectoryChildren(ctx context.Context, dir *scanmodel.Directory) ([]scanmodel.FSEntry, error)

DirectoryChildren retrieves the children of a directory from the repository.

func (r *Repo) DirectoryLinks(ctx context.Context, dirScan *model.DirectoryDAGScan) ([]model.LinkParams, error)

DirectoryLinks retrieves link parameters for a given directory scan.

func (*Repo) FilesToDAGScan

func (r *Repo) FilesToDAGScan(ctx context.Context, uploadID id.UploadID, count int) ([]FileInfo, error)

func (*Repo) FindNodeByCIDAndSpaceDID

func (r *Repo) FindNodeByCIDAndSpaceDID(ctx context.Context, c cid.Cid, spaceDID did.DID) (dagsmodel.Node, error)

func (*Repo) FindOrCreateDirectory

func (r *Repo) FindOrCreateDirectory(ctx context.Context, path string, lastModified time.Time, mode fs.FileMode, checksum []byte, sourceID id.SourceID, spaceDID did.DID) (*scanmodel.Directory, bool, error)

FindOrCreateDirectory finds or creates a directory entry in the repository with the given parameters. If the directory already exists, it returns the existing directory and false. If the directory does not exist, it creates a new directory entry and returns it along with true.

func (*Repo) FindOrCreateFile

func (r *Repo) FindOrCreateFile(ctx context.Context, path string, lastModified time.Time, mode fs.FileMode, size uint64, checksum []byte, sourceID id.SourceID, spaceDID did.DID) (*scanmodel.File, bool, error)

FindOrCreateFile finds or creates a file entry in the repository with the given parameters. If the file already exists, it returns the existing file and false. If the file does not exist, it creates a new file entry and returns it along with true.

func (*Repo) FindOrCreateRawNode

func (r *Repo) FindOrCreateRawNode(ctx context.Context, cid cid.Cid, size uint64, spaceDID did.DID, path string, sourceID id.SourceID, offset uint64) (*model.RawNode, bool, error)

FindOrCreateRawNode finds or creates a raw node in the repository. If a node with the same CID, size, path, source ID, and offset already exists, it returns that node. If not, it creates a new raw node with the provided parameters.

func (*Repo) FindOrCreateSpace

func (r *Repo) FindOrCreateSpace(ctx context.Context, did did.DID, name string, options ...spacesmodel.SpaceOption) (*spacesmodel.Space, error)

FindOrCreateSpace finds an existing space or creates a new one in the repository with the given name and options.

func (*Repo) FindOrCreateUnixFSNode

func (r *Repo) FindOrCreateUnixFSNode(ctx context.Context, cid cid.Cid, size uint64, spaceDID did.DID, ufsdata []byte) (*model.UnixFSNode, bool, error)

FindOrCreateUnixFSNode finds or creates a UnixFS node in the repository. If a node with the same CID, size, and ufsdata already exists, it returns that node. If not, it creates a new UnixFS node with the provided parameters.

func (*Repo) FindOrCreateUploads

func (r *Repo) FindOrCreateUploads(ctx context.Context, spaceDID did.DID, sourceIDs []id.SourceID) ([]*model.Upload, error)

FindOrCreateUploads creates uploads for a given space and source IDs.

func (*Repo) ForEachNode

func (r *Repo) ForEachNode(ctx context.Context, shardID id.ShardID, yield func(node dagsmodel.Node, shardOffset uint64) error) error

func (*Repo) GetFileByID

func (r *Repo) GetFileByID(ctx context.Context, fileID id.FSEntryID) (*scanmodel.File, error)

GetFileByID retrieves a file by its unique ID from the repository.

func (*Repo) GetShardByID

func (r *Repo) GetShardByID(ctx context.Context, shardID id.ShardID) (*model.Shard, error)

func (*Repo) GetSourceByID

func (r *Repo) GetSourceByID(ctx context.Context, sourceID id.SourceID) (*sourcemodel.Source, error)

GetSourceByID retrieves a source by its unique ID from the repository.

func (*Repo) GetSourceByName

func (r *Repo) GetSourceByName(ctx context.Context, name string) (*sourcemodel.Source, error)

GetSourceByName retrieves a source by its name from the repository.

func (*Repo) GetSpaceByDID

func (r *Repo) GetSpaceByDID(ctx context.Context, spaceDID did.DID) (*spacesmodel.Space, error)

GetSpaceByDID retrieves a space by its unique DID from the repository.

func (*Repo) GetSpaceByName

func (r *Repo) GetSpaceByName(ctx context.Context, name string) (*spacesmodel.Space, error)

GetSpaceByName retrieves a space by its name from the repository.

func (*Repo) GetUploadByID

func (r *Repo) GetUploadByID(ctx context.Context, uploadID id.UploadID) (*model.Upload, error)

GetUploadByID retrieves an upload by its unique ID from the repository.

func (*Repo) HasIncompleteChildren

func (r *Repo) HasIncompleteChildren(ctx context.Context, directoryScans *model.DirectoryDAGScan) (bool, error)

HasIncompleteChildren returns whether the given directory scan has at least one child scan that is not completed.

func (*Repo) IncompleteDAGScansForUpload

func (r *Repo) IncompleteDAGScansForUpload(ctx context.Context, uploadID id.UploadID) ([]model.DAGScan, error)

func (*Repo) LinksForCID

func (r *Repo) LinksForCID(ctx context.Context, c cid.Cid, sd did.DID) ([]*model.Link, error)

func (*Repo) ListSpaceSources

func (r *Repo) ListSpaceSources(ctx context.Context, spaceDID did.DID) ([]id.SourceID, error)

ListSpaceSources lists all sources associated with a given space DID.

func (*Repo) ListSpaces

func (r *Repo) ListSpaces(ctx context.Context) ([]*spacesmodel.Space, error)

ListSpaces lists all spaces in the repository.

func (*Repo) NodesByShard

func (r *Repo) NodesByShard(ctx context.Context, shardID id.ShardID, startOffset uint64) ([]dagsmodel.Node, error)

func (*Repo) RemoveSourceFromSpace

func (r *Repo) RemoveSourceFromSpace(ctx context.Context, spaceDID did.DID, sourceID id.SourceID) error

RemoveSourceFromSpace removes a source from a space in the repository.

func (*Repo) ShardedFiles

func (r *Repo) ShardedFiles(ctx context.Context, uploadID id.UploadID, count int) ([]FileInfo, error)

func (*Repo) ShardsForUploadByState

func (r *Repo) ShardsForUploadByState(ctx context.Context, uploadID id.UploadID, state model.ShardState) ([]*model.Shard, error)

func (*Repo) TotalBytesToScan

func (r *Repo) TotalBytesToScan(ctx context.Context, uploadID id.UploadID) (uint64, error)

func (*Repo) UpdateDAGScan

func (r *Repo) UpdateDAGScan(ctx context.Context, dagScan model.DAGScan) error

UpdateDAGScan updates a DAG scan in the repository.

func (*Repo) UpdateShard

func (r *Repo) UpdateShard(ctx context.Context, shard *model.Shard) error

UpdateShard updates a DAG scan in the repository.

func (*Repo) UpdateSource

func (r *Repo) UpdateSource(ctx context.Context, src *sourcemodel.Source) error

UpdateSource updates the given source in the repository.

func (*Repo) UpdateUpload

func (r *Repo) UpdateUpload(ctx context.Context, upload *model.Upload) error

UpdateUpload implements uploads.Repo.

type RowScanner

type RowScanner interface {
	Scan(dest ...any) error
}

RowScanner can scan a row into a set of destinations. It should not be confused with sql.Scanner, which is used to scan a single value.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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