MCPcopy Create free account
hub / github.com/WiseLibs/better-sqlite3 / Database

Class Database

src/objects/database.hpp:1–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class Database : public Napi::ObjectWrap<Database> {
2public:
3
4 explicit Database(const Napi::CallbackInfo& info);
5 ~Database();
6
7 // Whenever this is used, addon->dbs.erase() must be invoked beforehand.
8 void CloseHandles();
9
10 // Used to support ordered containers.
11 class CompareDatabase { public:
12 inline bool operator() (Database const * const a, Database const * const b) const {
13 return a < b;
14 }
15 };
16 class CompareStatement { public:
17 inline bool operator() (Statement const * const a, Statement const * const b) const {
18 return Statement::Compare(a, b);
19 }
20 };
21 class CompareBackup { public:
22 inline bool operator() (Backup const * const a, Backup const * const b) const {
23 return Backup::Compare(a, b);
24 }
25 };
26
27 // Proper error handling logic for when an sqlite3 operation fails.
28 void ThrowDatabaseError(Napi::Env env);
29 static void ThrowSqliteError(Napi::Env env, Addon* addon, sqlite3* db_handle);
30 static void ThrowSqliteError(Napi::Env env, Addon* addon, const char* message, int code);
31
32 // Allows Statements to log their executed SQL.
33 bool Log(Napi::Env env, sqlite3_stmt* handle);
34
35 // Allow Statements to manage themselves when created and garbage collected.
36 inline void AddStatement(Statement* stmt) { stmts.insert(stmts.end(), stmt); }
37 inline void RemoveStatement(Statement* stmt) { stmts.erase(stmt); }
38
39 // Allow Backups to manage themselves when created and garbage collected.
40 inline void AddBackup(Backup* backup) { backups.insert(backups.end(), backup); }
41 inline void RemoveBackup(Backup* backup) { backups.erase(backup); }
42
43 // A view for Statements to see and modify Database state.
44 // The order of these fields must exactly match their actual order.
45 struct State {
46 const bool open;
47 bool busy;
48 const bool safe_ints;
49 const bool unsafe_mode;
50 bool was_js_error;
51 const bool has_logger;
52 unsigned short iterators;
53 Addon* const addon;
54 };
55
56 inline State* GetState() { return reinterpret_cast<State*>(&open); }
57 inline sqlite3* GetHandle() { return db_handle; }
58 inline Addon* GetAddon() { return addon; }
59
60 // Identifies objects that are backed by this class (see IsInstanceOf).

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected