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

Method NewRecord

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

Source from the content-addressed store, hash-verified

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);

Callers

nothing calls this directly

Calls 1

SafeCallFunction · 0.85

Tested by

no test coverage detected