MCPcopy Index your code
hub / github.com/perkeep/perkeep / sql

Method sql

pkg/sorted/sqlkv/sqlkv.go:70–96  ·  view source on GitHub ↗

sql returns the query, replacing placeholders using PlaceHolderFunc, and /*TPRE*/ with TablePrefix.

(sqlStmt string)

Source from the content-addressed store, hash-verified

68// sql returns the query, replacing placeholders using PlaceHolderFunc,
69// and /*TPRE*/ with TablePrefix.
70func (kv *KeyValue) sql(sqlStmt string) string {
71 // string manipulation is done only once
72 kv.queriesInitOnce.Do(func() {
73 kv.queries = make(map[string]string, 8) // we have 8 queries in this file
74 kv.replacer = strings.NewReplacer("/*TPRE*/", kv.TablePrefix)
75 })
76 kv.queriesMu.RLock()
77 sqlQuery, ok := kv.queries[sqlStmt]
78 kv.queriesMu.RUnlock()
79 if ok {
80 return sqlQuery
81 }
82 kv.queriesMu.Lock()
83 // check again, now holding the lock
84 if sqlQuery, ok = kv.queries[sqlStmt]; ok {
85 kv.queriesMu.Unlock()
86 return sqlQuery
87 }
88 sqlQuery = sqlStmt
89 if f := kv.PlaceHolderFunc; f != nil {
90 sqlQuery = f(sqlQuery)
91 }
92 sqlQuery = kv.replacer.Replace(sqlQuery)
93 kv.queries[sqlStmt] = sqlQuery
94 kv.queriesMu.Unlock()
95 return sqlQuery
96}
97
98type batchTx struct {
99 tx *sql.Tx

Callers 9

SetMethod · 0.95
DeleteMethod · 0.95
WipeMethod · 0.95
SetMethod · 0.80
DeleteMethod · 0.80
findFunction · 0.80
getFunction · 0.80
TestSqlFunction · 0.80
BenchmarkSqlFunction · 0.80

Implementers 6

memKeyspkg/sorted/mem.go
kvispkg/sorted/kvfile/kvfile.go
keyValuepkg/sorted/mongo/mongokv.go
KeyValuepkg/sorted/buffer/buffer.go
KeyValuepkg/sorted/sqlkv/sqlkv.go
kvispkg/sorted/leveldb/leveldb.go

Calls 5

LockMethod · 0.80
UnlockMethod · 0.80
RLockMethod · 0.65
RUnlockMethod · 0.65
fFunction · 0.50

Tested by 2

TestSqlFunction · 0.64
BenchmarkSqlFunction · 0.64