Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for IsDate and IsRegExp #3

Closed

Conversation

anisha-rohra
Copy link

No description provided.

src/statement.cc Outdated
@@ -3,6 +3,7 @@
#include "macros.h"
#include "database.h"
#include "statement.h"
#include <napi.h>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add this. I'm guessing it may already be in one of the include file.s

src/statement.cc Outdated
@@ -164,13 +165,17 @@ void Statement::Work_AfterPrepare(uv_work_t* req) {

template <class T> Values::Field*
Statement::BindParameter(const Napi::Value source, T pos) {
if (source.IsString()/* || source.IsRegExp()*/) {
Napi::Function date_func = source.Env().Global().Get("Date").As<Function>();
Napi::Function regexp_func = source.Env().Global().Get("RegExp").As<Function>();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we cache these by creating in the Init function.

src/statement.cc Outdated
@@ -199,6 +204,8 @@ template <class T> Values::Field*
template <class T> T* Statement::Bind(const Napi::CallbackInfo& info, int start, int last) {
Napi::Env env = info.Env();
Napi::HandleScope scope(env);
Napi::Function date_func = env.Global().Get("Date").As<Function>();
Napi::Function regexp_func = env.Global().Get("RegExp").As<Function>();

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above about caching

src/database.cc Outdated
mode = info[pos++].As<Napi::Number>().Int32Value();
double orig_val = info[pos].As<Napi::Number>().DoubleValue();
double int_val = (double)info[pos].As<Napi::Number>().Int32Value();
if (orig_val == int_val) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check if this does the right thing for cases like Number.NEGATIVE_INFINITY
Number.POSITIVE_INFINITY etc?

//}
else if (OtherInstanceOf(source.As<Object>(), "RegExp")) {
std::string val = source.ToString().Utf8Value();
return new Values::Text(pos, val.length(), val.c_str());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can combine with earlier if

src/statement.cc Outdated
if (OtherIsInt(name.As<Number>())) {
baton->parameters.push_back(
BindParameter((object).Get(name), name.As<Napi::Number>().Int32Value()));
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if it is not an int32 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants