Ich würde Ihre Hilfe benötigen, da ich in Postgresql Daten zu kämpfen habe. Ich gehe davon aus, dass die Instanz von postgresql und der App auf der Bluemix-Plattform läuft. Wie auch immer, das Problem hängt mit Postgres zusammen.Nicht in der Lage, Daten in Postgresql zu speichern
Hier können Sie den Code finde ich zur Zeit bin mit Daten in Postgresl Speicherung:
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.urlencoded({
extended: true
}));
app.use(bodyParser.json());
var Q = require ('q');
var cfenv = require('cfenv');
const util = require('util');
const assert = require('assert');
var pg = require('pg');
var appEnv = cfenv.getAppEnv();
var services = appEnv.services;
var pg_services = services["compose-for-postgresql"];
// assert(!util.isUndefined(pg_services), "Must be bound to compose-for-postgresql services");
var credentials = pg_services[0].credentials;
var ca = new Buffer(credentials.ca_certificate_base64, 'base64');
var connectionString = credentials.uri;
var parse = require('pg-connection-string').parse;
config = parse(connectionString);
config.ssl = {
rejectUnauthorized: false,
ca: ca
}
var client = new pg.Client(config);
// This function to set up the connection with PostgreSQL database
module.exports.postgresql_database_connection = function() {
console.log("creating table");
client.connect(function(err) {
if (err) {
console.log("error connecting");
console.log(err);
}
else {
client.query('CREATE TABLE IF NOT EXISTS users (email varchar(256) PRIMARY KEY NOT NULL, name varchar(256) NOT NULL, surname varchar(256) NOT NULL, telephone varchar(256) NOT NULL, role varchar(256) NOT NULL, description varchar(256))', function (err,result){
if (err) {
console.log("error with query");
console.log(err);
}
else {
console.log("table created");
}
});
}
});
};
// This function is to create and store a new user into the PostgreSQL database with all the needed information
module.exports.postgresql_save_user = function(email, name, surname, role, telephone, description) {
console.log("reading parameters");
console.log("reading email : " + email);
var deferred = Q.defer();
// set up a new client using our config details
var client = new pg.Client(config);
client.connect(function(err) {
if (err) {
console.log("errore 1");
console.log(err);
deferred.reject();
}
else {
var queryText = 'INSERT INTO users(email,name,surname,telephone,role,description) VALUES(?, ?, ?, ?, ?, ?)';
// client.query(queryText, [email, name, surname, telephone, role, description], function (error,result){
client.query(queryText, ['email', 'name', 'surname', 'telephone', 'role', 'description'], function (error,result){
if (error) {
console.log("errore 2");
console.log(error);
deferred.reject();
}
else {
console.log("Saving the new user into the postegresql database: ");
console.log(result);
//check how result is printed and then manage it where called
deferred.resolve(result);
}
});
}
});
return deferred.promise;
};
ich den folgenden Fehler feststellen, und ich verstehe nicht, was es ist - ich habe es schon geprüft und die Tabelle wurde erfolgreich erstellt. Die Frage sollte
2017-06-19T14:09:51.54+0100 [APP/0] OUT { error: syntax error at or near ","
2017-06-19T14:09:51.54+0100 [APP/0] OUT at Connection.parseE (/home/vcap/app/node_modules/pg/lib/connection.js:567:11)
2017-06-19T14:09:51.54+0100 [APP/0] OUT at Connection.parseMessage (/home/vcap/app/node_modules/pg/lib/connection.js:391:17)
2017-06-19T14:09:51.54+0100 [APP/0] OUT at TLSSocket.<anonymous> (/home/vcap/app/node_modules/pg/lib/connection.js:129:22)
2017-06-19T14:09:51.54+0100 [APP/0] OUT at emitOne (events.js:96:13)
2017-06-19T14:09:51.54+0100 [APP/0] OUT at TLSSocket.emit (events.js:188:7)
2017-06-19T14:09:51.54+0100 [APP/0] OUT at readableAddChunk (_stream_readable.js:176:18)
2017-06-19T14:09:51.54+0100 [APP/0] OUT at TLSSocket.Readable.push (_stream_readable.js:134:10)
2017-06-19T14:09:51.54+0100 [APP/0] OUT at TLSWrap.onread (net.js:551:20)
2017-06-19T14:09:51.54+0100 [APP/0] OUT name: 'error',
2017-06-19T14:09:51.54+0100 [APP/0] OUT length: 83,
2017-06-19T14:09:51.54+0100 [APP/0] OUT severity: 'ERROR',
2017-06-19T14:09:51.54+0100 [APP/0] OUT code: '42601',
2017-06-19T14:09:51.54+0100 [APP/0] OUT hint: undefined,
2017-06-19T14:09:51.54+0100 [APP/0] OUT position: '81',
2017-06-19T14:09:51.54+0100 [APP/0] OUT internalPosition: undefined,
2017-06-19T14:09:51.54+0100 [APP/0] OUT internalQuery: undefined,
2017-06-19T14:09:51.54+0100 [APP/0] OUT where: undefined,
2017-06-19T14:09:51.54+0100 [APP/0] OUT column: undefined,
2017-06-19T14:09:51.54+0100 [APP/0] OUT dataType: undefined,
2017-06-19T14:09:51.54+0100 [APP/0] OUT file: 'scan.l',
2017-06-19T14:09:51.54+0100 [APP/0] OUT line: '1081',
2017-06-19T14:09:51.54+0100 [APP/0] OUT routine: 'scanner_yyerror' }
Können Sie ein Tag für die von Ihnen verwendete Programmiersprache hinzufügen? –