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

Class StatementIterator

src/objects/statement-iterator.hpp:1–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class StatementIterator : public Napi::ObjectWrap<StatementIterator> {
2public:
3
4 // The ~Statement destructor currently covers any state this object creates.
5 // Additionally, we actually DON'T want to revert stmt->locked or db_state
6 // ->iterators in this destructor, to ensure deterministic database access.
7 explicit StatementIterator(const Napi::CallbackInfo& info);
8 ~StatementIterator();
9
10 // Identifies objects that are backed by this class (see IsInstanceOf).
11 static const napi_type_tag TYPE_TAG;
12
13 static INIT(Init);
14
15private:
16
17 Napi::Value Next(Napi::Env env);
18 Napi::Value Return(Napi::Env env);
19 Napi::Value Throw(Napi::Env env);
20 void Cleanup();
21
22 static inline Napi::Object NewRecord(
23 Napi::Env env,
24 Napi::Value value,
25 Addon* addon,
26 bool done
27 ) {
28 assert(!addon->RecordFactory.IsEmpty());
29
30 // Fast path, using a factory function from JS land.
31 if (!done) {
32 napi_value arg = value;
33 return SafeCall(env, addon->RecordFactory.Value(), env.Undefined(), 1, &arg)
34 .As<Napi::Object>();
35 }
36
37 // Slow path, only used after the iterator is done.
38 napi_property_descriptor properties[2] = {};
39 properties[0].name = addon->cs.value.Value();
40 properties[0].value = value;
41 properties[0].attributes = DEFAULT_ATTRIBUTES;
42 properties[1].name = addon->cs.done.Value();
43 properties[1].value = Napi::Boolean::New(env, done);
44 properties[1].attributes = DEFAULT_ATTRIBUTES;
45
46 napi_value record;
47 napi_status status = napi_create_object(env, &record);
48 assert(status == napi_ok);
49 status = napi_define_properties(env, record, 2, properties);
50 assert(status == napi_ok); ((void)status);
51 return Napi::Object(env, record);
52 }
53
54 static inline Napi::Object DoneRecord(Napi::Env env, Addon* addon) {
55 return NewRecord(env, env.Undefined(), addon, true);
56 }
57
58 NODE_METHOD(JS_new);
59 static NODE_METHOD(JS_next);
60 static NODE_METHOD(JS_return);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected