pglens 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,221 @@
1
+ # pglens
2
+
3
+ A simple PostgreSQL database viewer tool. Perfect to quickly view and explore your PostgreSQL database through a web interface.
4
+
5
+ ## Features
6
+
7
+ - 🗂️ **Table Browser**: View all tables in your database in a clean, searchable sidebar
8
+ - 📊 **Data Viewer**: Browse table rows with a modern, easy-to-read interface
9
+ - 🪟 **Multiple Tabs**: Open multiple tables simultaneously in separate tabs
10
+ - 🔄 **Sorting**: Click column headers to sort data (client-side sorting on current view)
11
+ - 📄 **Pagination**: Navigate through large tables with Previous/Next buttons (100 rows per page)
12
+ - 🔍 **Table Search**: Quickly find tables by name using the search bar
13
+ - 👁️ **Column Visibility**: Show or hide columns to focus on what matters
14
+ - 📏 **Column Resizing**: Resize columns by dragging the column borders
15
+ - 🎨 **Theme Support**: Choose between light, dark, or system theme
16
+ - 🔄 **Refresh Data**: Reload table data with a single click
17
+ - ⚡ **Optimized Performance**: Uses cursor-based pagination for efficient large table navigation
18
+ - 🔒 **SSL Support**: Configurable SSL modes with automatic recommendations on connection errors
19
+ - 🚀 **Easy Setup**: Install globally and run with a single command
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ npm install -g pglens
25
+ ```
26
+
27
+ Or install locally in your project:
28
+
29
+ ```bash
30
+ npm install pglens
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ Run pglens with your PostgreSQL connection string and optional port:
36
+
37
+ ```bash
38
+ pglens --url postgresql://user:password@localhost:5432/dbname --port 54321
39
+ ```
40
+
41
+ ### Arguments
42
+
43
+ - `--url` (required): PostgreSQL connection string
44
+ - Format: `postgresql://user:password@host:port/database`
45
+ - Example: `postgresql://postgres:mypassword@localhost:5432/mydb`
46
+ - `--port` (optional): Port to run the web server on (default: 54321)
47
+ - `--sslmode` (optional): SSL mode for database connection (default: `prefer`)
48
+ - `disable`: Disable SSL encryption
49
+ - `require`: Require SSL, but don't verify certificate
50
+ - `prefer`: Prefer SSL, but allow non-SSL fallback (default)
51
+ - `verify-ca`: Require SSL and verify certificate authority
52
+ - `verify-full`: Require SSL and verify certificate and hostname
53
+
54
+ ### SSL Mode Examples
55
+
56
+ ```bash
57
+ # Use default SSL mode (prefer)
58
+ pglens --url postgresql://postgres:secret@localhost:5432/myapp
59
+
60
+ # Require SSL without certificate verification (for self-signed certs)
61
+ pglens --url postgresql://postgres:secret@localhost:5432/myapp --sslmode require
62
+
63
+ # Disable SSL (for local development)
64
+ pglens --url postgresql://postgres:secret@localhost:5432/myapp --sslmode disable
65
+
66
+ # Full certificate verification (for production)
67
+ pglens --url postgresql://postgres:secret@localhost:5432/myapp --sslmode verify-full
68
+ ```
69
+
70
+ ### Connection Troubleshooting
71
+
72
+ If you encounter connection errors, pglens will automatically analyze the error and suggest an appropriate SSL mode:
73
+
74
+ ```
75
+ ✗ Failed to connect to PostgreSQL database: self signed certificate
76
+
77
+ 💡 SSL Mode Recommendation: Try using --sslmode require
78
+ Current SSL mode: verify-full
79
+ Suggested command: Add --sslmode require to your command
80
+ ```
81
+
82
+ ### Basic Example
83
+
84
+ ```bash
85
+ pglens --url postgresql://postgres:secret@localhost:5432/myapp --port 54321
86
+ ```
87
+
88
+ Then open your browser to `http://localhost:54321` to view your database.
89
+
90
+ ## Running with PM2 (Server Deployment)
91
+
92
+ For production use on a server, you can run pglens as a persistent process using [PM2](https://pm2.keymetrics.io/), a process manager for Node.js applications.
93
+
94
+ ### Install PM2
95
+
96
+ ```bash
97
+ npm install -g pm2
98
+ ```
99
+
100
+ ### Start pglens with PM2
101
+
102
+ ```bash
103
+ pm2 start pglens -- --url postgresql://user:password@localhost:5432/dbname --port 54321
104
+ ```
105
+
106
+ Or with SSL mode:
107
+
108
+ ```bash
109
+ pm2 start pglens -- --url postgresql://user:password@localhost:5432/dbname --port 54321 --sslmode require
110
+ ```
111
+
112
+ Or use PM2's ecosystem file for better configuration:
113
+
114
+ **ecosystem.config.js:**
115
+
116
+ ```javascript
117
+ module.exports = {
118
+ apps: [
119
+ {
120
+ name: "pglens",
121
+ script: "pglens",
122
+ args: "--url postgresql://user:password@localhost:5432/dbname --port 54321 --sslmode require",
123
+ instances: 1,
124
+ autorestart: true,
125
+ watch: false,
126
+ max_memory_restart: "300M",
127
+ env: {
128
+ NODE_ENV: "production",
129
+ },
130
+ },
131
+ ],
132
+ };
133
+ ```
134
+
135
+ Then start with:
136
+
137
+ ```bash
138
+ pm2 start ecosystem.config.js
139
+ ```
140
+
141
+ ### Useful PM2 Commands
142
+
143
+ ```bash
144
+ # View running processes
145
+ pm2 list
146
+
147
+ # View logs
148
+ pm2 logs pglens
149
+
150
+ # Stop pglens
151
+ pm2 stop pglens
152
+
153
+ # Restart pglens
154
+ pm2 restart pglens
155
+
156
+ # Delete pglens from PM2
157
+ pm2 delete pglens
158
+
159
+ # Save PM2 process list (for auto-restart on reboot)
160
+ pm2 save
161
+
162
+ # Setup PM2 to start on system boot
163
+ pm2 startup
164
+ ```
165
+
166
+ ### Important Security Reminder
167
+
168
+ ⚠️ **Warning**: When running pglens on a server, ensure you:
169
+
170
+ - Use a reverse proxy (nginx, Apache) with authentication
171
+ - Restrict access via firewall rules
172
+ - Use HTTPS/TLS encryption
173
+ - Consider adding authentication middleware
174
+ - Never expose it directly to the internet without proper security measures
175
+
176
+ ## How It Works
177
+
178
+ 1. **Start the server**: Run the `pglens` command with your database URL
179
+ 2. **View tables**: The left sidebar shows all tables in your database
180
+ 3. **Search tables**: Use the search bar to quickly filter tables by name
181
+ 4. **Select a table**: Click on any table to view its data in a new tab
182
+ 5. **Multiple tabs**: Open multiple tables at once - each opens in its own tab
183
+ 6. **Sort data**: Click on column headers to sort the current view
184
+ 7. **Customize columns**: Use the "Columns" button to show/hide columns or resize them by dragging borders
185
+ 8. **Navigate pages**: Use Previous/Next buttons to load more rows (100 rows per page)
186
+ 9. **Refresh data**: Click the refresh button (↻) to reload the current table
187
+ 10. **Change theme**: Click the theme button (🌓) to switch between light, dark, or system theme
188
+
189
+ ## Development
190
+
191
+ To develop or modify pglens:
192
+
193
+ ```bash
194
+ # Clone or navigate to the project directory
195
+ cd pglens
196
+
197
+ # Install dependencies
198
+ npm install
199
+
200
+ # Run locally
201
+ node bin/pglens --url your-connection-string --port 54321
202
+ ```
203
+
204
+ ## Contributing
205
+
206
+ Contributions are welcome! Please read our [Contributing Guidelines](CONTRIBUTING.md) for details on:
207
+
208
+ - How to set up your development environment
209
+ - Code style and guidelines
210
+ - Pull request process
211
+ - Issue reporting
212
+
213
+ We appreciate all contributions, whether it's bug fixes, new features, documentation improvements, or feedback.
214
+
215
+ ## Security Note
216
+
217
+ This tool is designed for local development use only. It has no authentication and should **never** be exposed to the internet or untrusted networks. Always use it on localhost or within a trusted network environment.
218
+
219
+ ## License
220
+
221
+ MIT
package/bin/pglens ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { program } = require('commander');
4
+ const { startServer } = require('../src/server');
5
+
6
+ program
7
+ .name('pglens')
8
+ .description('A simple PostgreSQL database viewer tool')
9
+ .version('1.0.0')
10
+ .requiredOption('--url <url>', 'PostgreSQL connection string (e.g., postgresql://user:pass@localhost:5432/dbname)')
11
+ .option('--port <port>', 'Port to run the web server on', '54321')
12
+ .option('--sslmode <mode>', 'SSL mode: disable, require, prefer, verify-ca, verify-full', 'prefer')
13
+ .parse(process.argv);
14
+
15
+ const options = program.opts();
16
+
17
+ startServer(options.url, parseInt(options.port, 10), options.sslmode);
18
+