aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/data/get.go
diff options
context:
space:
mode:
authorJP Appel <jeanpierre.appel01@gmail.com>2025-06-30 17:18:45 -0400
committerJP Appel <jeanpierre.appel01@gmail.com>2025-06-30 18:54:51 -0400
commita4d86693394ba9b181b5928c1c6e8c31c9bb2b64 (patch)
tree8088d8d7c8c835b3e4c3590f1e3875d8e732d8cb /pkg/data/get.go
parent3168673bc2b57909213287a99b6151b4f1e0c439 (diff)
Implement compiled query execution
Diffstat (limited to 'pkg/data/get.go')
-rw-r--r--pkg/data/get.go23
1 files changed, 13 insertions, 10 deletions
diff --git a/pkg/data/get.go b/pkg/data/get.go
index 7cae03a..968789b 100644
--- a/pkg/data/get.go
+++ b/pkg/data/get.go
@@ -22,9 +22,9 @@ type Fill struct {
//
// Use to build documents and aliases from a database connection
type FillMany struct {
- docs map[string]*index.Document
- ids map[string]int
- Db *sql.DB
+ docs map[string]*index.Document
+ ids map[string]int
+ Db *sql.DB
}
func (f Fill) Get(ctx context.Context) (*index.Document, error) {
@@ -49,7 +49,7 @@ func (f FillMany) Get(ctx context.Context) (map[string]*index.Document, error) {
f.docs = make(map[string]*index.Document)
f.ids = make(map[string]int)
- if err := f.documents(ctx); err != nil {
+ if err := f.documents(ctx, nil); err != nil {
return nil, err
}
if err := f.tags(ctx); err != nil {
@@ -95,15 +95,19 @@ func (f *Fill) document(ctx context.Context) error {
return nil
}
-func (f *FillMany) documents(ctx context.Context) error {
- rows, err := f.Db.QueryContext(ctx, `
+// Fill document info for documents provided by rows (id, path, title, date, fileTime, meta)
+// pass nil rows to get all documents in the database.
+func (f *FillMany) documents(ctx context.Context, rows *sql.Rows) error {
+ if rows == nil {
+ rows, err := f.Db.QueryContext(ctx, `
SELECT id, path, title, date, fileTime, meta
FROM Documents
`)
- if err != nil {
- return err
+ if err != nil {
+ return err
+ }
+ defer rows.Close()
}
- defer rows.Close()
var id int
var docPath string
@@ -138,7 +142,6 @@ func (f *FillMany) documents(ctx context.Context) error {
return nil
}
-
func (f Fill) authors(ctx context.Context) error {
rows, err := f.Db.QueryContext(ctx, `
SELECT name