surveyjs / surveyjs-nodejs

This demo shows how to integrate SurveyJS components with a NodeJS backend.
https://surveyjs-nodejs.azurewebsites.net
Other
146 stars 93 forks source link

I want to change the db adapter from InMemoryDBAdapter to Postgresql one #11

Closed shin-deok closed 2 years ago

shin-deok commented 3 years ago

I'm a beginner about the surveyjs and the nodejs.

I want to know how I can change the db adapter from InMemoryDBAdapter to Postgresql one in Survey-Creator.

Thank you

tsv2013 commented 3 years ago

You can change it in this function https://github.com/surveyjs/surveyjs-nodejs/blob/master/index.js#L19-L23

shin-deok commented 3 years ago

Thank you, In fact, I already changed that function as blow.

1) var db = new dbadapter(); //var db = new inmemorydbadapter(req.session);

2) //var db = new inmemorydbadapter(req.session); var db = new PostgresDBAdapter();

But New survey I made was not saved in database. What is wrong I did?

Thank you.

tsv2013 commented 3 years ago

You need to create a database and write your connection string in the https://github.com/surveyjs/surveyjs-nodejs/blob/master/dbadapter.js file. Probably you will need to debug this file and change it according your needs.

shin-deok commented 3 years ago

I changed a database. So demo surveys are disappeared successfully. Thank you.

But I meet the new error as below when I clicked the 'Add' button on my creator page.

console.log(dbadapter: PostgresDBAdapter);

WARNING: Creating a duplicate database object for the same connection. at new PostgresDBAdapter (D:\100. VSCode_Projects\4_Survey_Creator\surveyjs-nodejs\dbadapter.js:6:12) at getDBAdapter (D:\100. VSCode_Projects\4_Survey_Creator\surveyjs-nodejs\index.js:23:12) at Layer.handle [as handle_request] (D:\100. VSCode_Projects\4_Survey_Creator\surveyjs-nodejs\node_modules\express\lib\router\layer.js:95:5)
at next (D:\100. VSCode_Projects\4_Survey_Creator\surveyjs-nodejs\node_modules\express\lib\router\route.js:137:13) at Route.dispatch (D:\100. VSCode_Projects\4_Survey_Creator\surveyjs-nodejs\node_modules\express\lib\router\route.js:112:3)

Please let me know how I can fix it. Thank you.

survey_error

tsv2013 commented 3 years ago

Probably you need to use connection pool or close/recreate connection as discussed here - https://stackoverflow.com/questions/62193189/how-to-fix-the-duplicate-database-object-for-the-same-connection-dynamodb-warn

zeigerpuppy commented 3 years ago

looks like a database schema is needed.

The error I get on connection to the DB is:

(node:16226) UnhandledPromiseRejectionWarning: error: relation "surveys" does not exist
tsv2013 commented 3 years ago

The schema is very simple: surveys table contains id, name, json fields results table contains id, surveyId, resultJson

zeigerpuppy commented 3 years ago

Thanks, I note that for users creating the DB in an existing postgres DB (not docker) then the init.sql file can be used to create the schema.

tsv2013 commented 3 years ago

This demo shows how to integrate SurveyJS products with the node.js backend. We're using here in-memory data base with very simple structure and suppose that one who wants to use PostgreSQL, or MySQL, or other DBMS is familiar with it. One can debug server endpoint calls and can see - what data are being passed and received during API calls.

tsv2013 commented 2 years ago

I've removed PostgreSQL DB adapter