mirror of
https://github.com/syncthing/syncthing.git
synced 2026-03-26 02:01:11 -04:00
Switch the database from LevelDB to SQLite, for greater stability and simpler code. Co-authored-by: Tommy van der Vorst <tommy@pixelspark.nl> Co-authored-by: bt90 <btom1990@googlemail.com>
45 lines
918 B
Go
45 lines
918 B
Go
// Copyright (C) 2025 The Syncthing Authors.
|
|
//
|
|
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
// You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
package sqlite
|
|
|
|
import "github.com/jmoiron/sqlx"
|
|
|
|
type txPreparedStmts struct {
|
|
*sqlx.Tx
|
|
stmts map[string]*sqlx.Stmt
|
|
}
|
|
|
|
func (p *txPreparedStmts) Preparex(query string) (*sqlx.Stmt, error) {
|
|
if p.stmts == nil {
|
|
p.stmts = make(map[string]*sqlx.Stmt)
|
|
}
|
|
stmt, ok := p.stmts[query]
|
|
if ok {
|
|
return stmt, nil
|
|
}
|
|
stmt, err := p.Tx.Preparex(query)
|
|
if err != nil {
|
|
return nil, wrap(err)
|
|
}
|
|
p.stmts[query] = stmt
|
|
return stmt, nil
|
|
}
|
|
|
|
func (p *txPreparedStmts) Commit() error {
|
|
for _, s := range p.stmts {
|
|
s.Close()
|
|
}
|
|
return p.Tx.Commit()
|
|
}
|
|
|
|
func (p *txPreparedStmts) Rollback() error {
|
|
for _, s := range p.stmts {
|
|
s.Close()
|
|
}
|
|
return p.Tx.Rollback()
|
|
}
|