Where Online Learning is simpler!
The C and C++ Include Header Files
cat -n /usr/include/nodejs/src/node_sqlite.h
1 #ifndef SRC_NODE_SQLITE_H_ 2 #define SRC_NODE_SQLITE_H_ 3 4 #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 5 6 #include "base_object.h" 7 #include "node_mem.h" 8 #include "sqlite3.h" 9 #include "util.h" 10 11 #include <map> 12 #include <unordered_set> 13 14 namespace node { 15 namespace sqlite { 16 17 class DatabaseOpenConfiguration { 18 public: 19 explicit DatabaseOpenConfiguration(std::string&& location) 20 : location_(std::move(location)) {} 21 22 inline const std::string& location() const { return location_; } 23 24 inline bool get_read_only() const { return read_only_; } 25 26 inline void set_read_only(bool flag) { read_only_ = flag; } 27 28 inline bool get_enable_foreign_keys() const { return enable_foreign_keys_; } 29 30 inline void set_enable_foreign_keys(bool flag) { 31 enable_foreign_keys_ = flag; 32 } 33 34 inline bool get_enable_dqs() const { return enable_dqs_; } 35 36 inline void set_enable_dqs(bool flag) { enable_dqs_ = flag; } 37 38 inline void set_timeout(int timeout) { timeout_ = timeout; } 39 40 inline int get_timeout() { return timeout_; } 41 42 inline void set_use_big_ints(bool flag) { use_big_ints_ = flag; } 43 44 inline bool get_use_big_ints() const { return use_big_ints_; } 45 46 inline void set_return_arrays(bool flag) { return_arrays_ = flag; } 47 48 inline bool get_return_arrays() const { return return_arrays_; } 49 50 inline void set_allow_bare_named_params(bool flag) { 51 allow_bare_named_params_ = flag; 52 } 53 54 inline bool get_allow_bare_named_params() const { 55 return allow_bare_named_params_; 56 } 57 58 inline void set_allow_unknown_named_params(bool flag) { 59 allow_unknown_named_params_ = flag; 60 } 61 62 inline bool get_allow_unknown_named_params() const { 63 return allow_unknown_named_params_; 64 } 65 66 private: 67 std::string location_; 68 bool read_only_ = false; 69 bool enable_foreign_keys_ = true; 70 bool enable_dqs_ = false; 71 int timeout_ = 0; 72 bool use_big_ints_ = false; 73 bool return_arrays_ = false; 74 bool allow_bare_named_params_ = true; 75 bool allow_unknown_named_params_ = false; 76 }; 77 78 class StatementSync; 79 class BackupJob; 80 81 class DatabaseSync : public BaseObject { 82 public: 83 DatabaseSync(Environment* env, 84 v8::Local<v8::Object> object, 85 DatabaseOpenConfiguration&& open_config, 86 bool open, 87 bool allow_load_extension); 88 void MemoryInfo(MemoryTracker* tracker) const override; 89 static void New(const v8::FunctionCallbackInfo<v8::Value>& args); 90 static void Open(const v8::FunctionCallbackInfo<v8::Value>& args); 91 static void IsOpenGetter(const v8::FunctionCallbackInfo<v8::Value>& args); 92 static void IsTransactionGetter( 93 const v8::FunctionCallbackInfo<v8::Value>& args); 94 static void Close(const v8::FunctionCallbackInfo<v8::Value>& args); 95 static void Prepare(const v8::FunctionCallbackInfo<v8::Value>& args); 96 static void Exec(const v8::FunctionCallbackInfo<v8::Value>& args); 97 static void Location(const v8::FunctionCallbackInfo<v8::Value>& args); 98 static void CustomFunction(const v8::FunctionCallbackInfo<v8::Value>& args); 99 static void AggregateFunction( 100 const v8::FunctionCallbackInfo<v8::Value>& args); 101 static void CreateSession(const v8::FunctionCallbackInfo<v8::Value>& args); 102 static void ApplyChangeset(const v8::FunctionCallbackInfo<v8::Value>& args); 103 static void EnableLoadExtension( 104 const v8::FunctionCallbackInfo<v8::Value>& args); 105 static void LoadExtension(const v8::FunctionCallbackInfo<v8::Value>& args); 106 void FinalizeStatements(); 107 void RemoveBackup(BackupJob* backup); 108 void AddBackup(BackupJob* backup); 109 void FinalizeBackups(); 110 void UntrackStatement(StatementSync* statement); 111 bool IsOpen(); 112 bool use_big_ints() const { return open_config_.get_use_big_ints(); } 113 bool return_arrays() const { return open_config_.get_return_arrays(); } 114 bool allow_bare_named_params() const { 115 return open_config_.get_allow_bare_named_params(); 116 } 117 bool allow_unknown_named_params() const { 118 return open_config_.get_allow_unknown_named_params(); 119 } 120 sqlite3* Connection(); 121 122 // In some situations, such as when using custom functions, it is possible 123 // that SQLite reports an error while JavaScript already has a pending 124 // exception. In this case, the SQLite error should be ignored. These methods 125 // enable that use case. 126 void SetIgnoreNextSQLiteError(bool ignore); 127 bool ShouldIgnoreSQLiteError(); 128 129 SET_MEMORY_INFO_NAME(DatabaseSync) 130 SET_SELF_SIZE(DatabaseSync) 131 132 private: 133 bool Open(); 134 void DeleteSessions(); 135 136 ~DatabaseSync() override; 137 DatabaseOpenConfiguration open_config_; 138 bool allow_load_extension_; 139 bool enable_load_extension_; 140 sqlite3* connection_; 141 bool ignore_next_sqlite_error_; 142 143 std::set<BackupJob*> backups_; 144 std::set<sqlite3_session*> sessions_; 145 std::unordered_set<StatementSync*> statements_; 146 147 friend class Session; 148 }; 149 150 class StatementSync : public BaseObject { 151 public: 152 StatementSync(Environment* env, 153 v8::Local<v8::Object> object, 154 BaseObjectPtr<DatabaseSync> db, 155 sqlite3_stmt* stmt); 156 void MemoryInfo(MemoryTracker* tracker) const override; 157 static v8::Local<v8::FunctionTemplate> GetConstructorTemplate( 158 Environment* env); 159 static BaseObjectPtr<StatementSync> Create(Environment* env, 160 BaseObjectPtr<DatabaseSync> db, 161 sqlite3_stmt* stmt); 162 static void All(const v8::FunctionCallbackInfo<v8::Value>& args); 163 static void Iterate(const v8::FunctionCallbackInfo<v8::Value>& args); 164 static void Get(const v8::FunctionCallbackInfo<v8::Value>& args); 165 static void Run(const v8::FunctionCallbackInfo<v8::Value>& args); 166 static void Columns(const v8::FunctionCallbackInfo<v8::Value>& args); 167 static void SourceSQLGetter(const v8::FunctionCallbackInfo<v8::Value>& args); 168 static void ExpandedSQLGetter( 169 const v8::FunctionCallbackInfo<v8::Value>& args); 170 static void SetAllowBareNamedParameters( 171 const v8::FunctionCallbackInfo<v8::Value>& args); 172 static void SetAllowUnknownNamedParameters( 173 const v8::FunctionCallbackInfo<v8::Value>& args); 174 static void SetReadBigInts(const v8::FunctionCallbackInfo<v8::Value>& args); 175 static void SetReturnArrays(const v8::FunctionCallbackInfo<v8::Value>& args); 176 v8::MaybeLocal<v8::Value> ColumnToValue(const int column); 177 v8::MaybeLocal<v8::Name> ColumnNameToName(const int column); 178 void Finalize(); 179 bool IsFinalized(); 180 181 SET_MEMORY_INFO_NAME(StatementSync) 182 SET_SELF_SIZE(StatementSync) 183 184 private: 185 ~StatementSync() override; 186 BaseObjectPtr<DatabaseSync> db_; 187 sqlite3_stmt* statement_; 188 bool return_arrays_ = false; 189 bool use_big_ints_; 190 bool allow_bare_named_params_; 191 bool allow_unknown_named_params_; 192 std::optional<std::map<std::string, std::string>> bare_named_params_; 193 bool BindParams(const v8::FunctionCallbackInfo<v8::Value>& args); 194 bool BindValue(const v8::Local<v8::Value>& value, const int index); 195 196 friend class StatementSyncIterator; 197 }; 198 199 class StatementSyncIterator : public BaseObject { 200 public: 201 StatementSyncIterator(Environment* env, 202 v8::Local<v8::Object> object, 203 BaseObjectPtr<StatementSync> stmt); 204 void MemoryInfo(MemoryTracker* tracker) const override; 205 static v8::Local<v8::FunctionTemplate> GetConstructorTemplate( 206 Environment* env); 207 static BaseObjectPtr<StatementSyncIterator> Create( 208 Environment* env, BaseObjectPtr<StatementSync> stmt); 209 static void Next(const v8::FunctionCallbackInfo<v8::Value>& args); 210 static void Return(const v8::FunctionCallbackInfo<v8::Value>& args); 211 212 SET_MEMORY_INFO_NAME(StatementSyncIterator) 213 SET_SELF_SIZE(StatementSyncIterator) 214 215 private: 216 ~StatementSyncIterator() override; 217 BaseObjectPtr<StatementSync> stmt_; 218 bool done_; 219 }; 220 221 using Sqlite3ChangesetGenFunc = int (*)(sqlite3_session*, int*, void**); 222 223 class Session : public BaseObject { 224 public: 225 Session(Environment* env, 226 v8::Local<v8::Object> object, 227 BaseObjectWeakPtr<DatabaseSync> database, 228 sqlite3_session* session); 229 ~Session() override; 230 template <Sqlite3ChangesetGenFunc sqliteChangesetFunc> 231 static void Changeset(const v8::FunctionCallbackInfo<v8::Value>& args); 232 static void Close(const v8::FunctionCallbackInfo<v8::Value>& args); 233 static v8::Local<v8::FunctionTemplate> GetConstructorTemplate( 234 Environment* env); 235 static BaseObjectPtr<Session> Create(Environment* env, 236 BaseObjectWeakPtr<DatabaseSync> database, 237 sqlite3_session* session); 238 239 void MemoryInfo(MemoryTracker* tracker) const override; 240 SET_MEMORY_INFO_NAME(Session) 241 SET_SELF_SIZE(Session) 242 243 private: 244 void Delete(); 245 sqlite3_session* session_; 246 BaseObjectWeakPtr<DatabaseSync> database_; // The Parent Database 247 }; 248 249 class UserDefinedFunction { 250 public: 251 UserDefinedFunction(Environment* env, 252 v8::Local<v8::Function> fn, 253 DatabaseSync* db, 254 bool use_bigint_args); 255 ~UserDefinedFunction(); 256 static void xFunc(sqlite3_context* ctx, int argc, sqlite3_value** argv); 257 static void xDestroy(void* self); 258 259 private: 260 Environment* env_; 261 v8::Global<v8::Function> fn_; 262 DatabaseSync* db_; 263 bool use_bigint_args_; 264 }; 265 266 } // namespace sqlite 267 } // namespace node 268 269 #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS 270 #endif // SRC_NODE_SQLITE_H_