Documentation
¶
Overview ¶
Package db manages the SQLite database connection and schema migrations.
Package db manages the SQLite database connection and schema migrations.
Index ¶
- func CreateSyncLog(ctx context.Context, db *sql.DB, log *SyncLog) error
- func InitDB(dbPath string) (*sql.DB, error)
- func MarkFileAsPushed(ctx context.Context, db *sql.DB, id string) error
- func SaveContent(ctx context.Context, db *sql.DB, c *Content) error
- func UpdateSyncLog(ctx context.Context, db *sql.DB, log *SyncLog) error
- func UpsertFile(ctx context.Context, db *sql.DB, f *File) (rowsAffected int64, isNew bool, err error)
- type Content
- type File
- func GetFileByID(ctx context.Context, db *sql.DB, id string) (*File, error)
- func GetFilesToPush(ctx context.Context, db *sql.DB) ([]*File, error)
- func ListFilesByFolder(ctx context.Context, db *sql.DB, folderPath string) ([]*File, error)
- func SearchFiles(ctx context.Context, db *sql.DB, queryStr string) ([]*File, error)
- type Scanner
- type SyncLog
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateSyncLog ¶
CreateSyncLog records the start of a synchronization run.
func InitDB ¶
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 ¶
MarkFileAsPushed marks a single file as pushed to Google Sheets.
func SaveContent ¶
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 ¶
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 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 ¶
GetFileByID retrieves a file record by its Google Drive ID. Returns nil, nil if the file is not found.
func GetFilesToPush ¶
GetFilesToPush retrieves all file records that haven't been pushed to Google Sheets.
func ListFilesByFolder ¶
ListFilesByFolder retrieves all file records within a specific folder path.
type Scanner ¶
Scanner is an interface that wraps the Scan method, implemented by *sql.Row and *sql.Rows.