76 void operator()(sqlite3 * db);
78 std::unique_ptr<sqlite3, Close> db;
89 void exec(
const std::string & stmt,
NeverAsync = {});
95 void setPersistWAL(
bool persist);
97 uint64_t getLastInsertedRowId();
98 uint64_t getRowsChanged();
110 void operator()(sqlite3_stmt * stmt);
114 std::unique_ptr<sqlite3_stmt, Finalize> stmt;
117 SQLiteStmt(sqlite3 * db,
const std::string & sql);
120 SQLiteStmt() =
default;
127 friend class SQLiteStmt;
130 unsigned int curArg = 1;
131 Use(SQLiteStmt & stmt);
140 Use &
operator () (std::string_view value,
bool notNull =
true);
141 Use &
operator () (
const unsigned char * data,
size_t len,
bool notNull =
true);
142 Use &
operator () (int64_t value,
bool notNull =
true);
156 std::string getStr(
int col);
157 std::optional<std::string> getStrNullable(
int col);
158 int64_t getInt(
int col);
159 bool isNull(
int col);
177 void operator()(sqlite3 * db);
179 std::unique_ptr<sqlite3, Rollback> db;
188struct SQLiteError : Error
196 int errNo, extendedErrNo, offset;
198 SQLiteError(
const char *path,
const char *errMsg,
int errNo,
int extendedErrNo,
int offset,
HintFmt && hf);
202 template<
typename...
Args>
203 SQLiteError(
const char *path,
const char *errMsg,
int errNo,
int extendedErrNo,
int offset,
const std::string & fs,
const Args & ... args)
204 : SQLiteError(path, errMsg, errNo, extendedErrNo, offset,
HintFmt(fs, args...))
207 template<
typename...
Args>
208 [[noreturn]]
static void throw_(sqlite3 * db,
const std::string & fs,
const Args & ... args) {
209 throw_(db,
HintFmt(fs, args...));
212 [[noreturn]]
static void throw_(sqlite3 * db,
HintFmt && hf);
218void handleSQLiteBusy(
const SQLiteBusy & e, std::chrono::time_point<std::chrono::steady_clock> & nextWarning);
219kj::Promise<Result<void>> handleSQLiteBusyAsync(
const SQLiteBusy & e, std::chrono::time_point<std::chrono::steady_clock> & nextWarning);
226 requires(!
requires(F f) { []<
typename T>(kj::Promise<T>) {}(f()); })
229 auto nextWarning = std::chrono::steady_clock::now() + std::chrono::seconds(1);
234 }
catch (SQLiteBusy & e) {
235 handleSQLiteBusy(e, nextWarning);
241 requires requires(F f) { []<
typename T>(kj::Promise<Result<T>>) {}(f()); }
244 return [](F fun) ->
decltype(fun()) {
245 auto nextWarning = std::chrono::steady_clock::now() + std::chrono::seconds(1);
248 kj::Promise<Result<void>> handleBusy{
nullptr};
250 if constexpr (std::is_same_v<
decltype(fun()), kj::Promise<Result<void>>>) {
251 LIX_TRY_AWAIT(fun());
252 co_return result::success();
254 co_return LIX_TRY_AWAIT(fun());
256 }
catch (SQLiteBusy & e) {
257 handleBusy = handleSQLiteBusyAsync(e, nextWarning);
259 co_return result::current_exception();
261 LIX_TRY_AWAIT(handleBusy);
bool next()
Definition sqlite.cc:227
void exec()
Definition sqlite.cc:221
Use & operator()(std::string_view value, bool notNull=true)
Definition sqlite.cc:179
void isCache()
Definition sqlite.cc:102
This file defines two main structs/classes used in nix error handling.
SQLiteTxnType
Definition sqlite.hh:40
@ Exclusive
Definition sqlite.hh:61
@ Immediate
Definition sqlite.hh:55
@ Deferred
Definition sqlite.hh:49
SQLiteOpenMode
Definition sqlite.hh:19
@ Immutable
Definition sqlite.hh:37
@ NoCreate
Definition sqlite.hh:29
@ Normal
Definition sqlite.hh:24
auto retrySQLite(F fun, NeverAsync={})
Definition sqlite.hh:227
std::string Path
Definition types.hh:28