sql-preview 0.5.11

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Mehul Fadnavis
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # SQL Preview for VS Code
2
+
3
+ A Visual Studio Code extension for connecting to **Trino** databases, running SQL queries, and visualizing results directly within your editor.
4
+
5
+ ## Features
6
+
7
+ - **SQL Query Execution**: Run SQL queries against Trino databases directly from VS Code.
8
+ - **Interactive Results View**: View query results in a high-performance AG Grid table with sorting, filtering, and resizing.
9
+ - **Code Lens Integration**: Execute queries with a single click from your `.sql` files.
10
+ - **Client-Server Architecture**: Uses a dedicated background daemon for reliable connection management and query execution.
11
+ - **Secure Password Storage**: Passwords are encrypted using the OS keyring via VS Code's SecretStorage API.
12
+ - **MCP Integration (Beta)**: Exposes database tools to AI agents via the Model Context Protocol.
13
+
14
+ ## Usage
15
+
16
+ ### Running Queries
17
+
18
+ 1. Open a `.sql` file.
19
+ 2. **Code Lens**: Click "Run Query" above the SQL block.
20
+ 3. **Command Palette**: Open the palette (`Cmd+Shift+P`) and run `SQL Preview: Run Query`.
21
+ 4. **Shortcut**: Press `Cmd+Enter` (Mac) or `Ctrl+Enter` (Windows/Linux) to run the query.
22
+
23
+ ### Viewing Results
24
+
25
+ Results appear in the **SQL Preview** panel.
26
+
27
+ - **Sort**: Click column headers.
28
+ - **Filter**: Use the text boxes below headers.
29
+ - **Export**: Right-click to copy cells.
30
+
31
+ ## Architecture
32
+
33
+ This extension uses a robust **Client-Server** model:
34
+
35
+ 1. **Extension (Client)**: The VS Code frontend that handles UI, commands, and configuration.
36
+ 2. **Daemon (Server)**: A separate Node.js process that manages database connections and executes queries.
37
+ 3. **Communication**: The Client and Daemon communicate via the **Model Context Protocol (MCP)** over local sockets.
38
+
39
+ This separation ensures that long-running queries do not block the VS Code UI and provides a stable environment for database interactions.
40
+
41
+ ## Configuration
42
+
43
+ Add the following configuration to your `settings.json`:
44
+
45
+ ```json
46
+ {
47
+ "sqlPreview.defaultConnector": "trino",
48
+ "sqlPreview.host": "trino-coordinator.example.com",
49
+ "sqlPreview.port": 443,
50
+ "sqlPreview.user": "your-username",
51
+ "sqlPreview.catalog": "hive",
52
+ "sqlPreview.schema": "default",
53
+ "sqlPreview.ssl": true,
54
+ "sqlPreview.sslVerify": true,
55
+ "sqlPreview.maxRowsToDisplay": 1000,
56
+ "sqlPreview.logLevel": "INFO" // Options: DEBUG, INFO, WARN, ERROR
57
+ }
58
+ ```
59
+
60
+ ### Secure Password Management
61
+
62
+ For security, passwords are never stored in plain text.
63
+
64
+ 1. **Set Password**: Run the command `SQL Preview: Set Database Password` or click "Set Password" in the Settings UI.
65
+ 2. **Clear Password**: Run `SQL Preview: Clear Stored Password`.
66
+
67
+ ## 🤖 Model Context Protocol (MCP) Integration (Beta)
68
+
69
+ This extension includes a built-in MCP server that allows AI assistants (like Claude) to interact with your database.
70
+
71
+ ### Enabling MCP
72
+
73
+ 1. Open VS Code Settings.
74
+ 2. Set `sqlPreview.mcpEnabled` to `true`.
75
+ 3. (Optional) Set `sqlPreview.mcpSafeMode` to `true` (default) to restrict AI to read-only queries.
76
+ 4. Restart the extension or run `SQL Preview: Restart Background Server`.
77
+
78
+ ### Available Tools
79
+
80
+ When enabled, the following tools are available to MCP clients:
81
+
82
+ - `run_query`: Execute a SQL query.
83
+ - `list_tables`: List tables in a schema.
84
+ - `describe_table`: Show table schema.
85
+ - `get_ddl`: Get the CREATE TABLE statement.
86
+
87
+ ## Project Structure
88
+
89
+ ```
90
+ sql-preview/
91
+ ├── src/
92
+ │ ├── extension.ts # Main extension entry point (Client)
93
+ │ ├── server/ # Daemon process (Server)
94
+ │ │ ├── Daemon.ts # Server entry point
95
+ │ │ └── DaemonMcpServer.ts # MCP implementation
96
+ │ ├── connectors/ # Database connectors (Trino)
97
+ │ └── ui/ # Webview logic
98
+ └── webviews/ # Frontend assets (React/HTML/CSS)
99
+ ```
100
+
101
+ ## Development
102
+
103
+ 1. **Clone**: `git clone ...`
104
+ 2. **Install**: `npm install`
105
+ 3. **Build**: `npm run build`
106
+ 4. **Debug**: Press `F5` to start the Extension Host.
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuthenticationError = exports.QueryError = exports.ConnectionError = exports.BaseError = void 0;
4
+ class BaseError extends Error {
5
+ constructor(message, details) {
6
+ super(message);
7
+ this.details = details;
8
+ this.name = this.constructor.name;
9
+ }
10
+ }
11
+ exports.BaseError = BaseError;
12
+ class ConnectionError extends BaseError {
13
+ constructor(message, details) {
14
+ super(message, details);
15
+ }
16
+ }
17
+ exports.ConnectionError = ConnectionError;
18
+ class QueryError extends BaseError {
19
+ constructor(message, query, details) {
20
+ super(message, details);
21
+ this.query = query;
22
+ }
23
+ }
24
+ exports.QueryError = QueryError;
25
+ class AuthenticationError extends BaseError {
26
+ constructor(message, details) {
27
+ super(message, details);
28
+ }
29
+ }
30
+ exports.AuthenticationError = AuthenticationError;
31
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/common/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,SAAU,SAAQ,KAAK;IAClC,YACE,OAAe,EACC,OAAgB;QAEhC,KAAK,CAAC,OAAO,CAAC,CAAC;QAFC,YAAO,GAAP,OAAO,CAAS;QAGhC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IACpC,CAAC;CACF;AARD,8BAQC;AAED,MAAa,eAAgB,SAAQ,SAAS;IAC5C,YAAY,OAAe,EAAE,OAAgB;QAC3C,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC1B,CAAC;CACF;AAJD,0CAIC;AAED,MAAa,UAAW,SAAQ,SAAS;IACvC,YACE,OAAe,EACC,KAAc,EAC9B,OAAgB;QAEhB,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAHR,UAAK,GAAL,KAAK,CAAS;IAIhC,CAAC;CACF;AARD,gCAQC;AAED,MAAa,mBAAoB,SAAQ,SAAS;IAChD,YAAY,OAAe,EAAE,OAAgB;QAC3C,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC1B,CAAC;CACF;AAJD,kDAIC"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LogLevel = void 0;
4
+ var LogLevel;
5
+ (function (LogLevel) {
6
+ LogLevel["DEBUG"] = "DEBUG";
7
+ LogLevel["INFO"] = "INFO";
8
+ LogLevel["WARN"] = "WARN";
9
+ LogLevel["ERROR"] = "ERROR";
10
+ })(LogLevel || (exports.LogLevel = LogLevel = {}));
11
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/common/types.ts"],"names":[],"mappings":";;;AAkCA,IAAY,QAKX;AALD,WAAY,QAAQ;IAClB,2BAAe,CAAA;IACf,yBAAa,CAAA;IACb,yBAAa,CAAA;IACb,2BAAe,CAAA;AACjB,CAAC,EALW,QAAQ,wBAAR,QAAQ,QAKnB"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.logger = exports.ConsoleLogger = void 0;
4
+ const types_1 = require("../common/types");
5
+ class ConsoleLogger {
6
+ constructor() {
7
+ this.logLevel = types_1.LogLevel.INFO;
8
+ const envLevel = process.env['SQL_PREVIEW_LOG_LEVEL'];
9
+ if (envLevel && Object.values(types_1.LogLevel).includes(envLevel)) {
10
+ this.logLevel = envLevel;
11
+ }
12
+ }
13
+ static getInstance() {
14
+ if (!ConsoleLogger.instance) {
15
+ ConsoleLogger.instance = new ConsoleLogger();
16
+ }
17
+ return ConsoleLogger.instance;
18
+ }
19
+ shouldLog(level) {
20
+ const levels = [types_1.LogLevel.DEBUG, types_1.LogLevel.INFO, types_1.LogLevel.WARN, types_1.LogLevel.ERROR];
21
+ return levels.indexOf(level) >= levels.indexOf(this.logLevel);
22
+ }
23
+ info(message, data) {
24
+ if (this.shouldLog(types_1.LogLevel.INFO)) {
25
+ console.log(`[INFO] ${message}`, data ? JSON.stringify(data) : '');
26
+ }
27
+ }
28
+ error(message, error) {
29
+ if (this.shouldLog(types_1.LogLevel.ERROR)) {
30
+ console.error(`[ERROR] ${message}`, error);
31
+ }
32
+ }
33
+ warn(message, data) {
34
+ if (this.shouldLog(types_1.LogLevel.WARN)) {
35
+ console.warn(`[WARN] ${message}`, data ? JSON.stringify(data) : '');
36
+ }
37
+ }
38
+ debug(message, data) {
39
+ if (this.shouldLog(types_1.LogLevel.DEBUG)) {
40
+ console.debug(`[DEBUG] ${message}`, data ? JSON.stringify(data) : '');
41
+ }
42
+ }
43
+ }
44
+ exports.ConsoleLogger = ConsoleLogger;
45
+ exports.logger = ConsoleLogger.getInstance();
46
+ //# sourceMappingURL=ConsoleLogger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConsoleLogger.js","sourceRoot":"","sources":["../../src/server/ConsoleLogger.ts"],"names":[],"mappings":";;;AAAA,2CAA2C;AAE3C,MAAa,aAAa;IAIxB;QAFQ,aAAQ,GAAa,gBAAQ,CAAC,IAAI,CAAC;QAGzC,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;QACtD,IAAI,QAAQ,IAAI,MAAM,CAAC,MAAM,CAAC,gBAAQ,CAAC,CAAC,QAAQ,CAAC,QAAoB,CAAC,EAAE,CAAC;YACvE,IAAI,CAAC,QAAQ,GAAG,QAAoB,CAAC;QACvC,CAAC;IACH,CAAC;IAEM,MAAM,CAAC,WAAW;QACvB,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC;YAC5B,aAAa,CAAC,QAAQ,GAAG,IAAI,aAAa,EAAE,CAAC;QAC/C,CAAC;QACD,OAAO,aAAa,CAAC,QAAQ,CAAC;IAChC,CAAC;IAEO,SAAS,CAAC,KAAe;QAC/B,MAAM,MAAM,GAAG,CAAC,gBAAQ,CAAC,KAAK,EAAE,gBAAQ,CAAC,IAAI,EAAE,gBAAQ,CAAC,IAAI,EAAE,gBAAQ,CAAC,KAAK,CAAC,CAAC;QAC9E,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAChE,CAAC;IAEM,IAAI,CAAC,OAAe,EAAE,IAAc;QACzC,IAAI,IAAI,CAAC,SAAS,CAAC,gBAAQ,CAAC,IAAI,CAAC,EAAE,CAAC;YAClC,OAAO,CAAC,GAAG,CAAC,UAAU,OAAO,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CA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