-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_github.go
More file actions
104 lines (88 loc) · 3.02 KB
/
Copy pathdb_github.go
File metadata and controls
104 lines (88 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
// Package dalgo2ghingitdb provides a DALgo database adapter for reading inGitDB repositories from GitHub using the GitHub API.
// It supports read-only access to public repositories with no authentication required.
// Future versions will support authentication and write operations for private repositories.
package dalgo2ghingitdb
import (
"context"
"fmt"
"github.com/dal-go/dalgo/dal"
"github.com/dal-go/dalgo/recordset"
"github.com/ingitdb/ingitdb-go/ingitdb"
)
var _ dal.DB = (*githubDB)(nil)
// NewGitHubDB creates a GitHub repository adapter.
// Note: Definition is required for most operations, so prefer NewGitHubDBWithDef.
func NewGitHubDB(cfg Config) (dal.DB, error) {
reader, err := NewGitHubFileReader(cfg)
if err != nil {
return nil, err
}
db := &githubDB{
cfg: cfg,
fileReader: reader.(*githubFileReader),
}
return db, nil
}
func NewGitHubDBWithDef(cfg Config, def *ingitdb.Definition) (dal.DB, error) {
if def == nil {
return nil, fmt.Errorf("definition is required")
}
reader, err := NewGitHubFileReader(cfg)
if err != nil {
return nil, err
}
db := &githubDB{
cfg: cfg,
def: def,
fileReader: reader.(*githubFileReader),
}
return db, nil
}
type githubDB struct {
// dal.NoConcurrency: GitHub API rate limits make concurrent connections
// from a single client process counterproductive. The conservative
// default surfaces the right answer to callers sizing worker pools.
dal.NoConcurrency
cfg Config
def *ingitdb.Definition
fileReader *githubFileReader
}
func (db *githubDB) ID() string {
return DatabaseID
}
func (db *githubDB) Adapter() dal.Adapter {
return dal.NewAdapter(DatabaseID, "v0.0.1")
}
func (db *githubDB) Schema() dal.Schema {
return nil
}
func (db *githubDB) RunReadonlyTransaction(ctx context.Context, f dal.ROTxWorker, options ...dal.TransactionOption) error {
_ = options
tx := readonlyTx{db: db}
return f(ctx, tx)
}
func (db *githubDB) RunReadwriteTransaction(ctx context.Context, f dal.RWTxWorker, options ...dal.TransactionOption) error {
_ = options
tx := readwriteTx{readonlyTx: readonlyTx{db: db}}
return f(ctx, tx)
}
func (db *githubDB) Get(ctx context.Context, record dal.Record) error {
tx := readonlyTx{db: db}
return tx.Get(ctx, record)
}
func (db *githubDB) Exists(ctx context.Context, key *dal.Key) (bool, error) {
_, _ = ctx, key
return false, fmt.Errorf("exists is not implemented by %s", DatabaseID)
}
func (db *githubDB) GetMulti(ctx context.Context, records []dal.Record) error {
_, _ = ctx, records
return fmt.Errorf("getmulti is not implemented by %s", DatabaseID)
}
func (db *githubDB) ExecuteQueryToRecordsReader(ctx context.Context, query dal.Query) (dal.RecordsReader, error) {
_, _ = ctx, query
return nil, fmt.Errorf("query is not implemented by %s", DatabaseID)
}
func (db *githubDB) ExecuteQueryToRecordsetReader(ctx context.Context, query dal.Query, options ...recordset.Option) (dal.RecordsetReader, error) {
_, _, _ = ctx, query, options
return nil, fmt.Errorf("query is not implemented by %s", DatabaseID)
}