mirror of
https://github.com/go-shiori/shiori.git
synced 2025-10-02 01:36:45 +08:00
* refactor: Improve SQLite performance with connection pooling and retry logic * feat: Add withTx and withTxRetry methods to SQLiteDatabase for handling database locks * refactor: add Init command to all databases * refactor: Improve transaction handling with retry and error management * refactor: Remove panic/recover pattern in transaction handling * refactor: Replace `errors.WithStack` with `fmt.Errorf` in transaction methods * docs: Add docstrings to `withTx` and `withTxRetry` methods in SQLite database implementation * feat: use new withTxRetry in SaveBookmarks * feat: sqlite inmmediate transactions by default * refactor: Split SQLiteDatabase into separate writer and reader dbbase instances * refactor: Update Init method to configure both reader and writer database connections * feat: use writer/reader sqlite databases * refactor: Replace all read calls to use the `reader` database instance * refactor: Replace errors.WithStack with fmt.Errorf and add nil checks refactor: Replace errors.WithStack with fmt.Errorf and add proper error handling fix: Handle potential database connection errors with improved error wrapping refactor: Replace errors.WithStack with fmt.Errorf and improve error handling refactor: Replace error handling with fmt.Errorf and proper nil checks refactor: Replace errors.WithStack with fmt.Errorf and add nil error checks refactor: Replace errors.WithStack with fmt.Errorf and add nil checks in sqlite.go refactor: Replace errors.WithStack with fmt.Errorf and add nil checks refactor: Replace errors.WithStack with fmt.Errorf and improve error handling refactor: Replace remaining errors.WithStack with fmt.Errorf in sqlite.go * refactor: Use withTxRetry for SetDatabaseSchemaVersion method * fix: Simplify error handling in GetBookmark and GetAccount methods * refactor: Remove duplicated non-nil error checks in sqlite.go fix: duplicated non-nil checks * tests: use testutil instead of a manual in memory sqlite db * fix: openbsd sqlite connection
39 lines
908 B
Go
39 lines
908 B
Go
//go:build openbsd
|
|
// +build openbsd
|
|
|
|
package database
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/jmoiron/sqlx"
|
|
|
|
_ "git.sr.ht/~emersion/go-sqlite3-fts5"
|
|
_ "github.com/mattn/go-sqlite3"
|
|
)
|
|
|
|
// OpenSQLiteDatabase creates and open connection to new SQLite3 database.
|
|
func OpenSQLiteDatabase(ctx context.Context, databasePath string) (sqliteDB *SQLiteDatabase, err error) {
|
|
// Open database
|
|
rwDB, err := sqlx.ConnectContext(ctx, "sqlite", databasePath)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error opening writer database: %w", err)
|
|
}
|
|
|
|
rDB, err := sqlx.ConnectContext(ctx, "sqlite", databasePath)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error opening reader database: %w", err)
|
|
}
|
|
|
|
sqliteDB = &SQLiteDatabase{
|
|
writer: &dbbase{rwDB},
|
|
reader: &dbbase{rDB},
|
|
}
|
|
|
|
if err := sqliteDB.Init(ctx); err != nil {
|
|
return nil, fmt.Errorf("error initializing database: %w", err)
|
|
}
|
|
|
|
return sqliteDB, nil
|
|
}
|