Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2c173fe

Browse files
author
tsv2013
committed
2 parents 90dccdc + 450ef2a commit 2c173fe

File tree

7 files changed

+139
-876
lines changed

7 files changed

+139
-876
lines changed

‎README.md‎

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# SurveyJS + NodeJS + PostgreSQL Demo Example
22

3-
This demo shows how to integrate [SurveyJS](https://surveyjs.io/) components with a NodeJS backend with PostgreSQL database as a storage.
3+
This demo shows how to integrate [SurveyJS](https://surveyjs.io/) components with a NodeJS backend using a PostgreSQL database as a storage.
44

55
[View Demo Online](https://surveyjs-nodejs.azurewebsites.net/)
66

@@ -10,18 +10,41 @@ This demo must not be used as a real service as it doesn't cover such real-world
1010

1111
## Run the Application
1212

13-
Install [NodeJS](https://nodejs.org/) on your machine.
14-
Install [Docker Desktop](https://docs.docker.com/desktop/) on your machine.
15-
After that, run the following commands:
13+
1. Install [NodeJS](https://nodejs.org/) and [Docker Desktop](https://docs.docker.com/desktop/) on your machine.
1614

17-
```bash
18-
git clone https://github.com/surveyjs/surveyjs-nodejs-complex.git
19-
cd surveyjs-nodejs-complex
20-
docker compose up -d
21-
```
15+
2. Run the following commands:
2216

23-
Open http://localhost:9080 in your web browser.
17+
```bash
18+
git clone https://github.com/surveyjs/surveyjs-nodejs-postgresql.git
19+
cd surveyjs-nodejs-postgresql
20+
docker compose up -d
21+
```
22+
23+
3. Open http://localhost:9080 in your web browser.
2424

2525
## Client-Side App
2626

27-
The client-side part is the `surveyjs-react-client` React application. The current project includes only the application's build artifacts in the /public folder. Refer to the [surveyjs-react-client](https://github.com/surveyjs/surveyjs-react-client) repo for full code and information about the application.
27+
The client-side part is the `surveyjs-react-client` React application. The current project includes only the application's build artifacts in the [public](./public/) directory. Refer to the [`surveyjs-react-client`](https://github.com/surveyjs/surveyjs-react-client) repo for full code and information about the application.
28+
29+
## Integrate SurveyJS with PostgreSQL
30+
31+
SurveyJS communicates with any database using JSON objects that contain either survey schemas or user responses. An SQL database should have two tables to store these objects: `surveys` and `results`. You can use the following SQL script to create them: [`surveyjs.sql`](postgres/initdb/surveyjs.sql). The diagram below shows the structure of these tables:
32+
33+
![SurveyJS: The structure of database tables](https://github.com/surveyjs/surveyjs-nodejs-postgresql/assets/18551316/176a0e1d-963c-4ec0-a11d-33631aa05770)
34+
35+
To modify data in the `surveys` and `results` tables, you need to implement several JavaScript functions. According to the tasks they perform, these functions can be split into three modules:
36+
37+
- **SQL query builder**
38+
JS functions that construct CRUD SQL queries (see the [`sql-crud-adapter.js`](express-app/db-adapters/sql-crud-adapter.js) file).
39+
40+
- **SQL query runner**
41+
JS functions that execute queries in an SQL database. The repository you are viewing includes a query runner for PostgreSQL databases (see the [`postgres.js`](express-app/db-adapters/postgres.js) file). You can use it as an example to create a query runner for any other SQL database.
42+
43+
- **Survey storage**
44+
JS functions that provide an API for working with survey schemas and user responses (see the [`survey-storage.js`](express-app/db-adapters/survey-storage.js) file). This API is used by the NodeJS application router (see the [`index.js`](express-app/index.js) file).
45+
46+
These modules interact with each other as shown on the following diagram:
47+
48+
![SurveyJS PostgreSQL Integration](https://github.com/surveyjs/surveyjs-nodejs-postgresql/assets/18551316/2676bb99-d5a1-40fb-b0bb-c780c382e177)
49+
50+
If you want to integrate SurveyJS with other databases, you can modify or replace the query builder and query runner without changing the survey storage module. This approach is applied to MongoDB integration in the following repository: [`surveyjs-nodejs-mongodb`](https://github.com/surveyjs/surveyjs-nodejs-mongodb).

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /