KeyValue implements the sorted.KeyValue interface using an *sql.DB.
| 33 | |
| 34 | // KeyValue implements the sorted.KeyValue interface using an *sql.DB. |
| 35 | type KeyValue struct { |
| 36 | DB *sql.DB |
| 37 | |
| 38 | // SetFunc is an optional func to use when REPLACE INTO does not exist |
| 39 | SetFunc func(*sql.DB, string, string) error |
| 40 | BatchSetFunc func(*sql.Tx, string, string) error |
| 41 | |
| 42 | // PlaceHolderFunc optionally replaces ? placeholders |
| 43 | // with the right ones for the rdbms in use. |
| 44 | PlaceHolderFunc func(string) string |
| 45 | |
| 46 | // Gate optionally limits concurrent access. |
| 47 | // |
| 48 | // This originally existed just for SQLite, whose driver likes |
| 49 | // to return "the database is locked" |
| 50 | // (perkeep.org/issue/114), so this keeps some pressure |
| 51 | // off. But we still trust SQLite to deal with concurrency in |
| 52 | // most cases. |
| 53 | // |
| 54 | // It's also used to limit the number of MySQL connections. |
| 55 | Gate *syncutil.Gate |
| 56 | |
| 57 | // TablePrefix optionally provides a prefix for SQL table |
| 58 | // names. This is typically "dbname.", ending in a period. |
| 59 | TablePrefix string |
| 60 | |
| 61 | queriesInitOnce sync.Once // guards initialization of both queries and replacer |
| 62 | replacer *strings.Replacer |
| 63 | |
| 64 | queriesMu sync.RWMutex |
| 65 | queries map[string]string |
| 66 | } |
| 67 | |
| 68 | // sql returns the query, replacing placeholders using PlaceHolderFunc, |
| 69 | // and /*TPRE*/ with TablePrefix. |
nothing calls this directly
no outgoing calls
no test coverage detected