@indiekitai/pg-complete 0.1.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,114 @@
1
+ # @indiekitai/pg-complete
2
+
3
+ Smart PostgreSQL autocomplete engine for Node.js — ported from [pgcli](https://github.com/dbcli/pgcli).
4
+
5
+ ## Features
6
+
7
+ - **SQL keyword completion** — context-aware keyword suggestions
8
+ - **Table/view name completion** — suggests tables and views from your database
9
+ - **Column name completion** — context-aware, knows which table you're referencing
10
+ - **Schema-qualified completion** — `public.users`, `inventory.products`
11
+ - **Function name completion** — built-in + database functions
12
+ - **JOIN ON suggestions** — FK-based and name-based join conditions
13
+ - **Alias awareness** — works with table aliases (`FROM users u`)
14
+ - **Fuzzy matching** — type `ur` to match `users`, `user_roles`
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install @indiekitai/pg-complete
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ### With database connection
25
+
26
+ ```typescript
27
+ import { PgCompleter } from '@indiekitai/pg-complete';
28
+
29
+ const completer = new PgCompleter('postgresql://localhost/mydb');
30
+ await completer.refresh(); // Load schema metadata
31
+
32
+ const results = completer.complete('SELECT * FROM us');
33
+ // → [{ text: 'users', type: 'table' }, { text: 'user_roles', type: 'table' }]
34
+
35
+ const results2 = completer.complete('SELECT users.');
36
+ // → [{ text: 'id', type: 'column' }, { text: 'name', type: 'column' }, ...]
37
+ ```
38
+
39
+ ### With pre-loaded metadata
40
+
41
+ ```typescript
42
+ import { PgCompleter } from '@indiekitai/pg-complete';
43
+
44
+ const completer = new PgCompleter();
45
+ completer.setMetadata({
46
+ tables: {
47
+ public: {
48
+ users: [
49
+ { name: 'id', datatype: 'integer', hasDefault: true, default_: null, foreignKeys: [] },
50
+ { name: 'name', datatype: 'text', hasDefault: false, default_: null, foreignKeys: [] },
51
+ ],
52
+ },
53
+ },
54
+ views: {},
55
+ functions: {},
56
+ datatypes: {},
57
+ });
58
+
59
+ const results = completer.complete('SELECT * FROM ');
60
+ ```
61
+
62
+ ### CLI
63
+
64
+ ```bash
65
+ # Interactive mode with database
66
+ npx @indiekitai/pg-complete postgresql://localhost/mydb
67
+
68
+ # Type \c <partial-sql> to see completions
69
+ sql> \c SELECT * FROM us
70
+ users [table]
71
+ user_roles [table]
72
+ ```
73
+
74
+ ### MCP Server
75
+
76
+ ```bash
77
+ npx pg-complete-mcp
78
+ ```
79
+
80
+ Exposes `pg_complete` and `pg_connect` tools over MCP stdio protocol.
81
+
82
+ ## API
83
+
84
+ ### `PgCompleter`
85
+
86
+ #### `constructor(connectionString?: string | PgCompleterOptions)`
87
+
88
+ Create a new completer. Optionally provide a connection string or options.
89
+
90
+ #### `async refresh(): Promise<void>`
91
+
92
+ Connect to the database and load schema metadata.
93
+
94
+ #### `complete(text: string, cursorPos?: number): Completion[]`
95
+
96
+ Get completions for the given SQL text at the cursor position.
97
+
98
+ #### `setMetadata(meta: SchemaMetadata, searchPath?: string[]): void`
99
+
100
+ Set metadata directly (for testing or pre-loaded scenarios).
101
+
102
+ ### `Completion`
103
+
104
+ ```typescript
105
+ interface Completion {
106
+ text: string; // The completion text
107
+ type: CompletionType; // 'keyword' | 'table' | 'view' | 'column' | 'function' | 'schema' | ...
108
+ meta?: string; // Additional info (e.g. column datatype)
109
+ }
110
+ ```
111
+
112
+ ## License
113
+
114
+ MIT