Code Monkey home page Code Monkey logo

Comments (3)

Lagovas avatar Lagovas commented on July 21, 2024

i want ask @mnaza to take nodejs part. i have some problem with jsthemis on C level and it's will be longer if i will try understand where is problem than he.
i updated existing code due to renaming acrawriter function and wrote code for example without zones but can't check that it works. Here is patch for nodejs part

diff --git a/examples/nodejs/examples.js b/examples/nodejs/examples.js
new file mode 100644
index 0000000..1ee0d91
--- /dev/null
+++ b/examples/nodejs/examples.js
@@ -0,0 +1,53 @@
+var acra = require('acrawriter');
+var pg = require('pg');
+var fs = require('fs')
+
+var raw_data = 'Test Message';
+
+var config = {
+  user: 'postgres',
+  database: 'acra', 
+  password: 'postgres',
+  host: 'localhost',
+  port: 9494, 
+  max: 10, 
+  idleTimeoutMillis: 30000,
+};
+
+var public_key = fs.readFileSync('.acrakeys/client_storage.pub')
+
+var pool = new pg.Pool(config);
+pool.connect(function(err, client, done) {
+  if(err) {
+    return console.error('error fetching client from pool', err);
+  }
+  client.query('CREATE TABLE IF NOT EXISTS testjs(id SERIAL PRIMARY KEY, data BYTEA, raw_data TEXT)', [], function(err, res) {
+    done();
+    if(err) {
+      return console.error('error running query', err);
+    }
+  });
+  client.query('insert into testjs (data, raw_data) values ($2, $3)', [acra.create_acrastruct(raw_data, public_key, ""), raw_data], function(err, res) {
+    done();
+    if(err) {
+      return console.error('error running query', err);
+    }
+  });
+
+  client.query('select data, raw_data from testjs', [], function(err, res) {
+    done();
+    if(err) {
+      return console.error('error running query', err);
+    }
+    for(i=0;i<res.rows.length;i++){
+        console.log(res.rows[i].data.toString('utf8'));
+        console.log(res.rows[i].raw_data.toString('utf8'));
+        console.log(" ");
+    }
+  });
+  done();
+});
+
+pool.on('error', function (err, client) {
+  console.error('idle client error', err.message, err.stack)
+})
\ No newline at end of file
diff --git a/examples/nodejs/examples_with_zone.js b/examples/nodejs/examples_with_zone.js
index a57d136..518247b 100644
--- a/examples/nodejs/examples_with_zone.js
+++ b/examples/nodejs/examples_with_zone.js
@@ -1,4 +1,4 @@
-var acra = require('acra');
+var acra = require('acrawriter');
 var pg = require('pg');
 var request = require('sync-request');
 
@@ -23,20 +23,20 @@ pool.connect(function(err, client, done) {
   if(err) {
     return console.error('error fetching client from pool', err);
   }
-  client.query('CREATE TABLE IF NOT EXISTS testjs(id SERIAL PRIMARY KEY, zone BYTEA, data BYTEA, raw_data TEXT)', [], function(err, res) {
+  client.query('CREATE TABLE IF NOT EXISTS testjs_zone(id SERIAL PRIMARY KEY, zone BYTEA, data BYTEA, raw_data TEXT)', [], function(err, res) {
     done();
     if(err) {
       return console.error('error running query', err);
     }
   });
-  client.query('insert into testjs (zone, data, raw_data) values ($1, $2, $3)', [zone.id, acra.create_acra_struct(raw_data, new Buffer(zone.public_key, 'base64'), zone.id), raw_data], function(err, res) {
+  client.query('insert into testjs_zone (zone, data, raw_data) values ($1, $2, $3)', [zone.id, acra.create_acra_struct(raw_data, new Buffer(zone.public_key, 'base64'), zone.id), raw_data], function(err, res) {
     done();
     if(err) {
       return console.error('error running query', err);
     }
   });
 
-  client.query('select zone, data, raw_data from testjs', [], function(err, res) {
+  client.query('select zone, data, raw_data from testjs_zone', [], function(err, res) {
     done();
     if(err) {
       return console.error('error running query', err);

from acra.

gene-eu-zz avatar gene-eu-zz commented on July 21, 2024

@mnaza?

from acra.

Lagovas avatar Lagovas commented on July 21, 2024

completed by #75

from acra.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.