Postgres driver in NodeJS C++ Addon - c++

I'm currently developing a C++ addon for NodeJS using the abstraction layer Nan. I would like to make a PostgreSQL request from this addon. But I get the following error:
module.js:597
return process.dlopen(module, path._makeLong(filename));
^
Error: ....cpp/build/Release/MyModule.node: undefined symbol: _ZTVN4pqxx14connect_directE
at Error (native)
at Object.Module._extensions..node (module.js:597:18)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (...cpp/test.js:1:77)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
Here is my binding.gyp:
{
"targets": [
{
"target_name": "MyModule",
"sources": [ "Main.cpp"],
"include_dirs": [
"<!(node -e \"require('nan')\")"
],
"cflags": [
"-fexceptions",
"-lpq",
"-lpqxx"
],
"cflags_cc": [
"-fexceptions",
"-lpq",
"-lpqxx"
]
}
]
}
And my Main.cpp file
#include <nan.h>
#include <iostream>
#include <pqxx/pqxx>
using namespace Nan;
using namespace v8;
using namespace std;
using namespace pqxx;
NAN_METHOD(MyModule) {
// Database connection
connection C(
"dbname = ... \
user = ... \
password = ... \
hostaddr = 127.0.0.1 \
port = 5432");
}
NAN_MODULE_INIT(Init) {
Nan::Set(target, New<String>("MyModule").ToLocalChecked(),
GetFunction(New<FunctionTemplate>(MyModule)).ToLocalChecked());
}
NODE_MODULE(parser, Init)
I'm stuck with this error and I didn't find any solution on the web. I would be nice if someone could help!

dlopen tries to load a shared library. However, this library misses a symbol, _ZTVN4pqxx14connect_directE. To decode it:
$ c++filt _ZTVN4pqxx14connect_directE`
vtable for pqxx::connect_direct
Therefore, you need to link a library to your library (addon), which has this symbol. (The postgres driver?)
Make sure your build system doesn't delay the linking, and the lib appears when your run ldd your_addon. If the driver is installed to a non-standard directory, you can experiment with setting LD_LIBRARY_PATH, as a temporary solution.

Related

Deploying JHipster generated app to AWS via ECS using AWS Fargate errors

Deploying generated app with JHipster(version: 5.8.2) to AWS using aws-containers sub-generator gives ERROR! Cannot find module 'aws-sdk'
$ jhipster import-jdl blog.jh.
Content of blog.jh:
application {
config {
baseName blog,
applicationType monolith,
packageName org.jhipster.blog,
authenticationType jwt,
prodDatabaseType mysql,
cacheProvider no,
enableHibernateCache false,
buildTool maven,
clientFramework angularX,
useSass false,
testFrameworks [protractor]
}
entities *
}
entity Blog {
name String required minlength(3),
handle String required minlength(2)
}
entity Entry {
title String required,
content TextBlob required,
date Instant required
}
entity Tag {
name String required minlength(2)
}
relationship ManyToOne {
Blog{user(login)} to User,
Entry{blog(name)} to Blog
}
relationship ManyToMany {
Entry{tag(name)} to Tag{entry}
}
paginate Entry, Tag with infinite-scroll
$ jhipster aws-containers
INFO! Using JHipster version installed locally in current project's node_modules
INFO! Executing jhipster:aws-containers
INFO! Options: from-cli: true
ERROR! Cannot find module 'aws-sdk'
{ Error: Cannot find module 'aws-sdk'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:582:15)
at Function.Module._load (internal/modules/cjs/loader.js:508:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous> (/home/stane/Work/Lab/JHipster/blog.aws-containers/node_modules/generator-jhipster/generators/aws-containers/lib/ssm.js:19:13)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3) code: 'MODULE_NOT_FOUND' }
$ npm install aws-sdk gave
ERROR! Cannot find module 'ora'
$ npm install ora
And it came to:
$ jhipster aws-containers
INFO! Using JHipster version installed locally in current project's node_modules
INFO! Executing jhipster:aws-containers
INFO! Options: from-cli: true
This AWS generator will help you deploy your JHipster app as a Docker container on AWS.
✔ Docker is installed
Installing AWS dependencies
✔ AWS credentials using profile default.
events.js:174
throw er; // Unhandled 'error' event
^
TypeError: ora is not a function
at spinner (/home/stane/Work/Lab/JHipster/blog.aws-containers/node_modules/generator-jhipster/generators/aws-containers/aws-client.js:120:21)
at Object.listRegions (/home/stane/Work/Lab/JHipster/blog.aws-containers/node_modules/generator-jhipster/generators/aws-containers/aws-client.js:142:12)
at module.exports.fetchRegion (/home/stane/Work/Lab/JHipster/blog.aws-containers/node_modules/generator-jhipster/generators/aws-containers/index.js:159:22)
at Object.<anonymous> (/home/stane/Work/Lab/JHipster/blog.aws-containers/node_modules/yeoman-generator/lib/index.js:418:27)
at /home/stane/Work/Lab/JHipster/blog.aws-containers/node_modules/run-async/index.js:25:25
at new Promise (<anonymous>)
at /home/stane/Work/Lab/JHipster/blog.aws-containers/node_modules/run-async/index.js:24:19
at self.env.runLoop.add.completed (/home/stane/Work/Lab/JHipster/blog.aws-containers/node_modules/yeoman-generator/lib/index.js:419:13)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
Emitted 'error' event at:
at Immediate.setImmediate (/home/stane/Work/Lab/JHipster/blog.aws-containers/node_modules/yeoman-generator/lib/index.js:427:22)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
at process.topLevelDomainCallback (domain.js:120:23)

Gulp unhandled error 182

I have a django blog project, and am trying to use bower to manage my packages.
When running 'gulp' from my console, I get the following error :
(py3) ➜ nomadpad git:(master) ✗ gulp
[15:16:15] Using gulpfile ~/code/nomadpad/gulpfile.js
[15:16:15] Starting 'css'...
[15:16:16] Finished 'css' after 1.23 s
[15:16:16] Starting 'html'...
[15:16:16] Finished 'html' after 3.38 ms
[15:16:16] Starting 'scripts'...
[15:16:16] Finished 'scripts' after 4.43 ms
[15:16:16] Starting 'default'...
[15:16:16] Finished 'default' after 38 μs
events.js:182
throw er; // Unhandled 'error' event
^
CssSyntaxError: /Users/davidmellor/code/nomadpad/bower_components/jquery/dist/jquery.js:756:9: Unknown word
at Input.error (/Users/davidmellor/code/nomadpad/node_modules/postcss/lib/input.js:119:22)
at Parser.unknownWord (/Users/davidmellor/code/nomadpad/node_modules/postcss/lib/parser.js:506:26)
at Parser.other (/Users/davidmellor/code/nomadpad/node_modules/postcss/lib/parser.js:171:18)
at Parser.parse (/Users/davidmellor/code/nomadpad/node_modules/postcss/lib/parser.js:84:26)
at parse (/Users/davidmellor/code/nomadpad/node_modules/postcss/lib/parse.js:24:16)
at new LazyResult (/Users/davidmellor/code/nomadpad/node_modules/postcss/lib/lazy-result.js:70:24)
at Processor.process (/Users/davidmellor/code/nomadpad/node_modules/postcss/lib/processor.js:117:12)
at /Users/davidmellor/code/nomadpad/node_modules/gulp-postcss/index.js:51:12
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:169:7)
My bower.json in the root folder looks like this :
{
"name": "blog_postcssgulp",
"description": "",
"main": "gulpfile.js",
"authors": [
"DMells <dave#davemellor.com>"
],
"license": "ISC",
"homepage": "https://github.com/DMells/nomadpad",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"jquery": "^3.3.1",
"modernizr": "^3.5.0"
}
}
I'm not sure what to do here, please can anyone assist?
Many thanks
If anyone else comes across this, I found the solution by removing my bower_components folder and then reinstalling bower, as well as the jquery package.
npm install bower --save-dev
And then the jquery package:
bower install jquery --save-dev

Apollo runscript failing on iOS?

Running the iOS runscript causes the following error. Any advice?
This happens to the sample project
/bin/sh -c /Users/aryan.ghassemi/Library/Developer/Xcode/DerivedData/FrontPage-djowwaikrpnoghhjhlxriwamylsv/Build/Intermediates/FrontPage.build/Debug-iphonesimulator/FrontPage.build/Script-9F672F2E1DB0053600974171.sh
/Users/aryan.ghassemi/.nvm/versions/node/v4.2.6/lib/node_modules/apollo-codegen/lib/cli.js:41
const [name, value] = header.split(/\s*:\s*/);
^
SyntaxError: Unexpected token [
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:442:10)
at startup (node.js:136:18)
at node.js:966:3
The version of Apollo.framework in your project requires apollo-codegen 0.15, but an unknown older version seems to be installed. Installing...
/Users/aryan.ghassemi/.nvm/versions/node/v4.2.6/bin/apollo-codegen -> /Users/aryan.ghassemi/.nvm/versions/node/v4.2.6/lib/node_modules/apollo-codegen/lib/cli.js
+ apollo-codegen#0.15.2
updated 1 package in 1.363s
++ exec apollo-codegen generate ./PostListViewController.graphql ./PostTableViewCell.graphql --schema schema.json --output API.swift
/Users/aryan.ghassemi/.nvm/versions/node/v4.2.6/lib/node_modules/apollo-codegen/lib/cli.js:41
const [name, value] = header.split(/\s*:\s*/);
^
SyntaxError: Unexpected token [
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:442:10)
at startup (node.js:136:18)
at node.js:966:3
Command /bin/sh failed with exit code 1
Script was running on an older version of node, updating to 6.9 fixed the issue

how to locate 'imqi.hpp' from node-gyp

I am trying to use "nan" module to call MQ_CONNECT() from node.js
See
Node.js and C/C++ integration: how to properly implement callbacks?
and
https://github.com/nodejs/nan
When I use "node-gyp" it says it can not find "imqi.hpp", the MQ header
As far as I can see, the path to MQ includes has to be provided in "binding.gyp", and I have tried this without success:
{
"targets": [
{
"target_name": "mqconn",
"sources": [
"initall.cc",
"mqconn.cc"
],
"include_dirs": [
"<!(node -e \"require('nan')\")",
"c:\MQ\tools\cplus\include"
]
}
]
}
Does anyboby have a clue on how to fix this ?
Sebastian.
PD.- of course, the file is where the path indicates:
c:\>dir c:\MQ\tools\cplus\include\imqi.hpp
Volume in drive C is OS
Volume Serial Number is 12AA-0601
Directory of c:\MQ\tools\cplus\include
27/06/2013 02:00 1.538 imqi.hpp
Because binding.gyp is in JSON, the String "c:\MQ\tools\cplus\include"is a standard JavaScript String, and therefore the \ needs to be escaped to \\.
So you should replace "c:\MQ\tools\cplus\include" into "c:\\MQ\\tools\\cplus\\include".
I hope that fixes the problem...

Karma/Jasmine testcases failing due to ngIdle module

Error: [$injector:modulerr] Failed to instantiate module ngIdle due to:
Error: [$injector:nomod] Module 'ngIdle' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
What is it that I am missing? If I don't include ngIdle module and remove the code for it's implementation then all my karma/jasmine tests are passing but with ngIdle included all of my 100+ testcases are failing and giving the above error. I have included ngIdle in karma.conf.js in this order
files: [
'app/bower_components/angular/angular.js',
'app/bower_components/angular-route/angular-route.js',
'app/bower_components/angular-touch/angular-touch.js',
'app/bower_components/angular-animate/angular-animate.js',
'app/bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js',
'app/bower_components/angular-mocks/angular-mocks.js',
'app/bower_components/angular-resource/angular-resource.js',
'app/bower_components/revolunet-angular-carousel/lib/angular-mobile.js',
'app/bower_components/revolunet-angular-carousel/src/angular-carousel.js',
'app/bower_components/jquery/dist/jquery.js',
'app/bower_components/angular-cookies/angular-cookies.min.js',
'app/bower_components/ng-idle/angular-idle.min.js',
'app/bower_components/ng-grid/ng-grid-2.0.11.min.js',
'app/js//*.js',
'test/spec//*.js'
],
Below is my bower.json so you get idea about the versions I am using if that is related
{
"name": "combo",
"version": "0.5.1",
"dependencies": {
"angular": "~1.3",
"angular-route": "~1.3",
"angular-touch": "~1.3",
"angular-animate": "~1.3",
"angular-resource": "~1.3",
"angular-cookies": "~1.3",
"angular-bootstrap": "~0.11.0",
"revolunet-angular-carousel": "~0.2.2",
"ng-grid": "~2.0.7",
"ng-idle": "latest",
"video.js": "~4",
"highcharts": "~3.0.7",
"jquery": "~2",
"jquery-ui": "~1.10.4",
"jqueryui-touch-punch": "git://github.com/furf/jquery-ui-touch-punch.git",
"angular-snap": "~1.4.1",
"snapjs": "latest"
},
"devDependencies": {
"angular-mocks": "~1.3",
"angular-scenario": "~1.3"
},
"resolutions": {
"angular": "~1.2.10",
"angular-touch": "~1.2.10",
"jquery": "^1.8.0"
}
}
You have to add angular-idle.min.js to your karma.conf.js.
files: [
//Configs
'config.js',
'lib/angular/angular.min.js',
'lib/angular-mocks/angular-mocks.js',
'lib/moment/moment.js',
'lib/ng-idle/angular-idle.min.js',
'lib/angular-moment/angular-moment.js',
// ... another libraries
],