go-io/specs/sqlite/RFC.md
Virgil 987507cae8 docs(specs): populate package RFCs
Co-Authored-By: Virgil <virgil@lethean.io>
2026-03-27 19:01:20 +00:00

5.8 KiB

sqlite

Import: dappco.re/go/core/io/sqlite Files: 1

Package sqlite provides a SQLite-backed implementation of the io.Medium interface.

Types

Medium

  • File: sqlite.go
  • Purpose: Medium is a SQLite-backed storage backend implementing the io.Medium interface.
  • Fields:
    • db *sql.DB — No doc comment in source.
    • table string — No doc comment in source.
  • Associated Methods:
    • func (m *Medium) Close() error — Close closes the underlying database connection.
    • func (m *Medium) Read(p string) (string, error) — Read retrieves the content of a file as a string.
    • func (m *Medium) Write(p, content string) error — Write saves the given content to a file, overwriting it if it exists.
    • func (m *Medium) EnsureDir(p string) error — EnsureDir makes sure a directory exists, creating it if necessary.
    • func (m *Medium) IsFile(p string) bool — IsFile checks if a path exists and is a regular file.
    • func (m *Medium) FileGet(p string) (string, error) — FileGet is a convenience function that reads a file from the medium.
    • func (m *Medium) FileSet(p, content string) error — FileSet is a convenience function that writes a file to the medium.
    • func (m *Medium) Delete(p string) error — Delete removes a file or empty directory.
    • func (m *Medium) DeleteAll(p string) error — DeleteAll removes a file or directory and all its contents recursively.
    • func (m *Medium) Rename(oldPath, newPath string) error — Rename moves a file or directory from oldPath to newPath.
    • func (m *Medium) List(p string) ([]fs.DirEntry, error) — List returns the directory entries for the given path.
    • func (m *Medium) Stat(p string) (fs.FileInfo, error) — Stat returns file information for the given path.
    • func (m *Medium) Open(p string) (fs.File, error) — Open opens the named file for reading.
    • func (m *Medium) Create(p string) (goio.WriteCloser, error) — Create creates or truncates the named file.
    • func (m *Medium) Append(p string) (goio.WriteCloser, error) — Append opens the named file for appending, creating it if it doesn't exist.
    • func (m *Medium) ReadStream(p string) (goio.ReadCloser, error) — ReadStream returns a reader for the file content.
    • func (m *Medium) WriteStream(p string) (goio.WriteCloser, error) — WriteStream returns a writer for the file content. Content is stored on Close.
    • func (m *Medium) Exists(p string) bool — Exists checks if a path exists (file or directory).
    • func (m *Medium) IsDir(p string) bool — IsDir checks if a path exists and is a directory.

Option

  • File: sqlite.go
  • Purpose: Option configures a Medium.
  • Underlying: func(*Medium)

fileInfo

  • File: sqlite.go
  • Purpose: fileInfo implements fs.FileInfo for SQLite entries.
  • Fields:
    • name string — No doc comment in source.
    • size int64 — No doc comment in source.
    • mode fs.FileMode — No doc comment in source.
    • modTime time.Time — No doc comment in source.
    • isDir bool — No doc comment in source.
  • Associated Methods:
    • func (fi *fileInfo) Name() string — No doc comment in source.
    • func (fi *fileInfo) Size() int64 — No doc comment in source.
    • func (fi *fileInfo) Mode() fs.FileMode — No doc comment in source.
    • func (fi *fileInfo) ModTime() time.Time — No doc comment in source.
    • func (fi *fileInfo) IsDir() bool — No doc comment in source.
    • func (fi *fileInfo) Sys() any — No doc comment in source.

dirEntry

  • File: sqlite.go
  • Purpose: dirEntry implements fs.DirEntry for SQLite listings.
  • Fields:
    • name string — No doc comment in source.
    • isDir bool — No doc comment in source.
    • mode fs.FileMode — No doc comment in source.
    • info fs.FileInfo — No doc comment in source.
  • Associated Methods:
    • func (de *dirEntry) Name() string — No doc comment in source.
    • func (de *dirEntry) IsDir() bool — No doc comment in source.
    • func (de *dirEntry) Type() fs.FileMode — No doc comment in source.
    • func (de *dirEntry) Info() (fs.FileInfo, error) — No doc comment in source.

sqliteFile

  • File: sqlite.go
  • Purpose: sqliteFile implements fs.File for SQLite entries.
  • Fields:
    • name string — No doc comment in source.
    • content []byte — No doc comment in source.
    • offset int64 — No doc comment in source.
    • mode fs.FileMode — No doc comment in source.
    • modTime time.Time — No doc comment in source.
  • Associated Methods:
    • func (f *sqliteFile) Stat() (fs.FileInfo, error) — No doc comment in source.
    • func (f *sqliteFile) Read(b []byte) (int, error) — No doc comment in source.
    • func (f *sqliteFile) Close() error — No doc comment in source.

sqliteWriteCloser

  • File: sqlite.go
  • Purpose: sqliteWriteCloser buffers writes and stores to SQLite on Close.
  • Fields:
    • medium *Medium — No doc comment in source.
    • path string — No doc comment in source.
    • data []byte — No doc comment in source.
  • Associated Methods:
    • func (w *sqliteWriteCloser) Write(p []byte) (int, error) — No doc comment in source.
    • func (w *sqliteWriteCloser) Close() error — No doc comment in source.

Functions

WithTable

  • File: sqlite.go
  • Signature: func WithTable(table string) Option
  • Purpose: WithTable sets the table name (default: "files").

New

  • File: sqlite.go
  • Signature: func New(dbPath string, opts ...Option) (*Medium, error)
  • Purpose: New creates a new SQLite Medium at the given database path. Use ":memory:" for an in-memory database.

cleanPath

  • File: sqlite.go
  • Signature: func cleanPath(p string) string
  • Purpose: cleanPath normalises a path for consistent storage. Uses a leading "/" before Clean to sandbox traversal attempts.