db

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package db manages the SQLite database connection and schema migrations.

Package db manages the SQLite database connection and schema migrations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateSyncLog

func CreateSyncLog(ctx context.Context, db *sql.DB, log *SyncLog) error

CreateSyncLog records the start of a synchronization run.

func InitDB

func InitDB(dbPath string) (*sql.DB, error)

InitDB establishes a connection to the SQLite database at the given path. It creates the database file and runs migrations if necessary. It also handles the expansion of the ~ symbol to the user's home directory.

func MarkFileAsPushed

func MarkFileAsPushed(ctx context.Context, db *sql.DB, id string) error

MarkFileAsPushed marks a single file as pushed to Google Sheets.

func SaveContent

func SaveContent(ctx context.Context, db *sql.DB, c *Content) error

SaveContent saves extracted markdown content to drive_contents (authoritative source) and updates the denormalized copy in drive_files.contents for fast access. The drive_files.contents column is a copy — drive_contents is the source of truth. If they diverge, drive_contents takes precedence.

func UpdateSyncLog

func UpdateSyncLog(ctx context.Context, db *sql.DB, log *SyncLog) error

UpdateSyncLog updates an existing sync log with results and completion status.

func UpsertFile

func UpsertFile(ctx context.Context, db *sql.DB, f *File) (rowsAffected int64, isNew bool, err error)

UpsertFile inserts a new file or updates an existing one based on ID. It uses the ON CONFLICT clause to handle updates. Returns rowsAffected: 1 if inserted/updated, 0 if skipped (no change). Also returns isNew: true if it was a new record.

Types

type Content

type Content struct {
	ID              int64
	FileID          string
	ContentMarkdown string
	ExtractedAt     time.Time
}

Content represents a record in the drive_contents table.

func GetContentByFileID

func GetContentByFileID(ctx context.Context, db *sql.DB, fileID string) (*Content, error)

GetContentByFileID retrieves the extracted content for a given file ID.

type File

type File struct {
	ID           string
	Name         string
	MimeType     string
	ParentID     string
	FolderPath   string
	Size         int64
	WebViewLink  string
	ModifiedTime time.Time
	SyncedAt     time.Time
	// Contents is a denormalized copy of drive_contents.content_markdown.
	// It is updated automatically by SaveContent. Do not update this field directly.
	// For the authoritative content, use GetContentByFileID.
	Contents         string
	Brief            string
	Category         string
	Tags             string
	ReorganizePath   string
	ContentExtracted bool
	SheetsPushed     bool
	CreatedAt        time.Time
	UpdatedAt        time.Time
}

File represents a record in the drive_files table.

func GetFileByID

func GetFileByID(ctx context.Context, db *sql.DB, id string) (*File, error)

GetFileByID retrieves a file record by its Google Drive ID. Returns nil, nil if the file is not found.

func GetFilesToPush

func GetFilesToPush(ctx context.Context, db *sql.DB) ([]*File, error)

GetFilesToPush retrieves all file records that haven't been pushed to Google Sheets.

func ListFilesByFolder

func ListFilesByFolder(ctx context.Context, db *sql.DB, folderPath string) ([]*File, error)

ListFilesByFolder retrieves all file records within a specific folder path.

func SearchFiles

func SearchFiles(ctx context.Context, db *sql.DB, queryStr string) ([]*File, error)

SearchFiles searches for files by name or folder path using a partial match.

type Scanner

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

Scanner is an interface that wraps the Scan method, implemented by *sql.Row and *sql.Rows.

type SyncLog

type SyncLog struct {
	ID           int64
	StartedAt    time.Time
	FinishedAt   time.Time
	Status       string
	FilesScanned int
	FilesNew     int
	FilesUpdated int
	FilesSkipped int
	ErrorMessage string
}

SyncLog keeps track of synchronization history

func GetLatestSyncLog

func GetLatestSyncLog(ctx context.Context, db *sql.DB) (*SyncLog, error)

GetLatestSyncLog retrieves the most recent synchronization record.

Jump to

Keyboard shortcuts

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