MCPcopy
hub / github.com/dnote/dnote / initSystemKV

Function initSystemKV

pkg/cli/infra/init.go:250–266  ·  view source on GitHub ↗
(db *database.DB, key string, val string)

Source from the content-addressed store, hash-verified

248}
249
250func initSystemKV(db *database.DB, key string, val string) error {
251 var count int
252 if err := db.QueryRow("SELECT count(*) FROM system WHERE key = ?", key).Scan(&count); err != nil {
253 return errors.Wrapf(err, "counting %s", key)
254 }
255
256 if count > 0 {
257 return nil
258 }
259
260 if _, err := db.Exec("INSERT INTO system (key, value) VALUES (?, ?)", key, val); err != nil {
261 db.Rollback()
262 return errors.Wrapf(err, "inserting %s %s", key, val)
263 }
264
265 return nil
266}
267
268// InitSystem inserts system data if missing
269func InitSystem(ctx context.DnoteCtx) error {

Callers 3

InitSystemFunction · 0.85
TestInitSystemKVFunction · 0.85

Calls 3

QueryRowMethod · 0.65
ExecMethod · 0.65
RollbackMethod · 0.65

Tested by 2

TestInitSystemKVFunction · 0.68