-
Notifications
You must be signed in to change notification settings - Fork 1
/
virtual_table.go
53 lines (45 loc) · 1.55 KB
/
virtual_table.go
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
package sysql
import (
"github.com/dean2021/go-sqlite3"
"github.com/dean2021/sysql/table"
)
type VirtualTable struct {
TablePlugin table.Table
Cursor sqlite3.VTabCursor
}
func (v *VirtualTable) Open() (sqlite3.VTabCursor, error) {
return v.Cursor, nil
}
func (v *VirtualTable) BestIndex(nConstraint []sqlite3.InfoConstraint, obl []sqlite3.InfoOrderBy) (*sqlite3.IndexResult, error) {
var used = make([]bool, len(nConstraint))
columns := v.TablePlugin.Columns()
for i, constraintInfo := range nConstraint {
if !constraintInfo.Usable {
continue
}
used[i] = true
// Lookup the column name given an index into the table column set.
if constraintInfo.Column < 0 || constraintInfo.Column >= len(columns) {
continue
}
columnType := columns[constraintInfo.Column].Type
if !table.SensibleComparison(columnType, constraintInfo.Op) {
continue
}
// Check if this constraint is on an index or required column.
//columnOptions := columns[constraintInfo.Column].Options
//if columnOptions != table.REQUIRED && (columnOptions&(table.INDEX|table.ADDITIONAL)) != 1 {
// // not indexed, let sqlite filter it
// continue
//}
// Add the constraint set to the table's tracked constraints.
columnName := columns[constraintInfo.Column].Name
v.Cursor.(*Cursor).Constraints = append(v.Cursor.(*Cursor).Constraints, table.Constraint{
Name: columnName,
Op: constraintInfo.Op,
})
}
return &sqlite3.IndexResult{Used: used}, nil
}
func (v *VirtualTable) Disconnect() error { return nil }
func (v *VirtualTable) Destroy() error { return nil }