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

Method BindObject

src/util/binder.cpp:120–154  ·  view source on GitHub ↗

Binds all named parameters using the values found in the given object. The number of successfully bound parameters is returned. If a named parameter is missing from the object, an error is thrown. This should only be invoked once per instance.

Source from the content-addressed store, hash-verified

118 // If a named parameter is missing from the object, an error is thrown.
119 // This should only be invoked once per instance.
120 int BindObject(Napi::Env env, Napi::Object obj, Statement* stmt) {
121 BindMap& bind_map = stmt->GetBindMap(env);
122 BindMap::Pair* pairs = bind_map.GetPairs();
123 int len = bind_map.GetSize();
124
125 for (int i = 0; i < len; ++i) {
126 Napi::String key = pairs[i].GetName(env);
127
128 // Check if the named parameter was provided.
129 bool has_property;
130 if (!SafeHasOwnProperty(env, obj, key, &has_property)) {
131 Fail(NULL, env, NULL);
132 return i;
133 }
134 if (!has_property) {
135 std::string param_name = key.Utf8Value();
136 Fail(ThrowRangeError, env, (std::string("Missing named parameter \"") + param_name + "\"").c_str());
137 return i;
138 }
139
140 // Get the current property value.
141 Napi::Value value = SafeGet(env, obj, key);
142 if (value.IsEmpty()) {
143 Fail(NULL, env, NULL);
144 return i;
145 }
146
147 BindValue(env, value, pairs[i].GetIndex());
148 if (!success) {
149 return i;
150 }
151 }
152
153 return len;
154 }
155
156 // Binds all parameters using the values found in the arguments object.
157 // Anonymous parameter values can be directly in the arguments object or in an Array.

Callers

nothing calls this directly

Calls 6

SafeHasOwnPropertyFunction · 0.85
SafeGetFunction · 0.85
GetPairsMethod · 0.80
GetSizeMethod · 0.80
GetNameMethod · 0.80
GetIndexMethod · 0.80

Tested by

no test coverage detected