feat: updat PostgreSQL integration guide & remove trailing whitespace in SheetJSPG.js
- Add testing with PostgresSQL 16.6.1 and pg 8.13.1 - Add Linux user creation instructions with password setup - Document SCRAM auth - Updated pg dependency to 8.13.1 - SheetJSPG.js removed trailing whitespace The guide now includes more detailed Linux setup instructions and authentication requirements for PostgreSQL deployments.
This commit is contained in:
parent
7315b4211c
commit
fb98fb9281
@ -36,6 +36,7 @@ This demo was tested in the following environments:
|
||||
|
||||
| Postgres | Connector Library | Date |
|
||||
|:---------|:------------------|:-----------|
|
||||
| `16.6.1` | `pg` (`8.13.1`) | 2024-12-03 |
|
||||
| `16.2.1` | `pg` (`8.11.4`) | 2024-03-31 |
|
||||
| `15.6` | `pg` (`8.11.4`) | 2024-03-31 |
|
||||
| `14.11` | `pg` (`8.11.4`) | 2024-03-31 |
|
||||
@ -144,9 +145,9 @@ The `sheet_to_pg_table` function:
|
||||
/* create table and load data given a worksheet and a PostgreSQL client */
|
||||
async function sheet_to_pg_table(client, worksheet, tableName) {
|
||||
if (!worksheet['!ref']) return;
|
||||
|
||||
|
||||
const range = XLSX.utils.decode_range(worksheet['!ref']);
|
||||
|
||||
|
||||
/* Extract headers from first row, clean names for PostgreSQL */
|
||||
const headers = [];
|
||||
for (let col = range.s.c; col <= range.e.c; col++) {
|
||||
@ -174,7 +175,7 @@ async function sheet_to_pg_table(client, worksheet, tableName) {
|
||||
|
||||
/* Delete table if it exists in the DB */
|
||||
await client.query(format('DROP TABLE IF EXISTS %I', tableName));
|
||||
|
||||
|
||||
/* Create table */
|
||||
const createTableSQL = format(
|
||||
'CREATE TABLE %I (%s)',
|
||||
@ -237,7 +238,7 @@ function deduceType(cells) {
|
||||
|
||||
function parseValue(cell, type) {
|
||||
if (!cell || cell.v == null) return null;
|
||||
|
||||
|
||||
switch (type) {
|
||||
case 'date':
|
||||
if (cell.t === 'd') { return cell.v.toISOString().split('T')[0]; }
|
||||
@ -297,8 +298,14 @@ wget -qO - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add
|
||||
sudo apt update
|
||||
sudo apt install postgresql-16
|
||||
sudo systemctl start postgresql
|
||||
|
||||
# Optional: Create user with password
|
||||
sudo -u postgres createuser -P $USER
|
||||
sudo -u postgres psql -c "ALTER USER $USER WITH SUPERUSER;"
|
||||
```
|
||||
|
||||
If running the optional user creation steps above, a PostgreSQL password will be required. [^69]
|
||||
|
||||
Run the command to start a local database instance.
|
||||
|
||||
</details>
|
||||
@ -312,6 +319,8 @@ dropdb SheetJSPG
|
||||
sudo -i -u postgres dropdb SheetJSPG
|
||||
```
|
||||
|
||||
[^69]: PostgreSQL on Linux uses [SCRAM authentication by default, which requires a password](https://www.postgresql.org/docs/current/auth-password.html)
|
||||
|
||||
:::info pass
|
||||
|
||||
If the server is running elsewhere, or if the username is different from the
|
||||
@ -353,7 +362,7 @@ npm init -y
|
||||
4) Install the `pg` connector module:
|
||||
|
||||
```bash
|
||||
npm i --save pg@8.11.4
|
||||
npm i --save pg@8.13.1
|
||||
```
|
||||
|
||||
5) Save the following example codeblock to `PGTest.js`:
|
||||
|
@ -46,7 +46,7 @@ function deduceType(cells) {
|
||||
|
||||
function parseValue(cell, type) {
|
||||
if (!cell || cell.v == null) return null;
|
||||
|
||||
|
||||
switch (type) {
|
||||
case 'date':
|
||||
if (cell.t === 'd') { return cell.v.toISOString().split('T')[0]; }
|
||||
@ -76,9 +76,9 @@ function parseValue(cell, type) {
|
||||
/* create table and load data given a worksheet and a PostgreSQL client */
|
||||
async function sheet_to_pg_table(client, worksheet, tableName) {
|
||||
if (!worksheet['!ref']) return;
|
||||
|
||||
|
||||
const range = XLSX.utils.decode_range(worksheet['!ref']);
|
||||
|
||||
|
||||
/* Extract headers from first row, clean names for PostgreSQL */
|
||||
const headers = [];
|
||||
for (let col = range.s.c; col <= range.e.c; col++) {
|
||||
@ -106,7 +106,7 @@ async function sheet_to_pg_table(client, worksheet, tableName) {
|
||||
|
||||
/* Delete table if it exists in the DB */
|
||||
await client.query(format('DROP TABLE IF EXISTS %I', tableName));
|
||||
|
||||
|
||||
/* Create table */
|
||||
const createTableSQL = format(
|
||||
'CREATE TABLE %I (%s)',
|
||||
|
Loading…
Reference in New Issue
Block a user