WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit f16996a

Browse files
committed
add file and more
0 parents  commit f16996a

File tree

15 files changed

+3817
-0
lines changed

15 files changed

+3817
-0
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
.vscode-test/
3+
*.vsix
4+
.env

.vscode-test.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { defineConfig } from '@vscode/test-cli';
2+
3+
export default defineConfig({
4+
files: 'test/**/*.test.js',
5+
});

.vscode/extensions.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
// See https://go.microsoft.com/fwlink/?LinkId=733558
3+
// for the documentation about the extensions.json format
4+
"recommendations": [
5+
"dbaeumer.vscode-eslint",
6+
"ms-vscode.extension-test-runner"
7+
]
8+
}

.vscode/launch.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// A launch configuration that launches the extension inside a new window
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
{
6+
"version": "0.2.0",
7+
"configurations": [
8+
{
9+
"name": "Run Extension",
10+
"type": "extensionHost",
11+
"request": "launch",
12+
"args": [
13+
"--extensionDevelopmentPath=${workspaceFolder}"
14+
]
15+
}
16+
]
17+
}

.vscodeignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.vscode/**
2+
.vscode-test/**
3+
test/**
4+
.gitignore
5+
.yarnrc
6+
vsc-extension-quickstart.md
7+
**/jsconfig.json
8+
**/*.map
9+
**/eslint.config.mjs
10+
**/.vscode-test.*
11+
12+
.git/**
13+
node_modules/**
14+
*.zip
15+
*.log
16+
test/**
17+
src/**

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 NarmadaWeb
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.

README.md

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# Ultimate PostgreSQL & SQLC Snippets for VS Code
2+
3+
Boost your database development productivity with this comprehensive collection of 50+ powerful snippets for PostgreSQL and SQLC. Designed to reduce boilerplate, enforce best practices, and speed up your workflow when working with modern SQL databases and the SQLC code generator.
4+
5+
## Features
6+
7+
* **Comprehensive SQLC Coverage**: Snippets for all core SQLC operations (`:one`, `:many`, `:exec`, `:batchexec`), including common patterns like returning inserted IDs, pagination, and batch inserts.
8+
* **Advanced SQLC Patterns**: Tackle complex scenarios with snippets for JOINs with aggregation, JSONB queries, array operations, full-text search, and transaction blocks.
9+
* **PostgreSQL DDL Mastery**: Quickly scaffold tables (with audit columns), indexes, enums, functions, and triggers (like auto-updating `updated_at`).
10+
* **Modern PostgreSQL Types**: Easy-to-use snippets for `UUID`, `JSONB` (with defaults), `TEXT[]` arrays, and full-text search setup (`TSVECTOR`).
11+
* **SQLC Configuration**: A ready-to-use `sqlc.yaml` template for both Go (pgx/v5) and Kotlin, including common type overrides.
12+
* **SQLC v2 Ready**: Includes snippets leveraging SQLC v2 features like named parameters (`@param`) and batch operations with returning values.
13+
* **Performance & Optimization**: Snippets for `EXPLAIN ANALYZE`, partial indexes, expression indexes, and Row Level Security (RLS) setup.
14+
* **Migration & Utility**: Helpers for creating extensions, adding/dropping columns, and common SQL expressions.
15+
* **Clear Descriptions**: Each snippet comes with a concise description of its purpose.
16+
* **Placeholder Guidance**: Smart placeholders (`${1:name}`, `${2|option1,option2|}`) guide you through snippet completion.
17+
18+
## Installation
19+
20+
1. Open **Visual Studio Code**.
21+
2. Go to the **Extensions** view (Ctrl+Shift+X or Cmd+Shift+X).
22+
3. Search for `[Your Extension Name Here - e.g., PostgreSQL SQLC Snippets Pro]`.
23+
4. Click **Install**.
24+
5. Reload VS Code if prompted.
25+
26+
## Usage
27+
28+
Simply start typing the snippet `prefix` in a `.sql` file (or any filetype you configure snippets for, like `.sqlc`, `.query.sql`), and VS Code's IntelliSense will suggest the available snippets. Press `Tab` or `Enter` to insert the snippet. Use `Tab` to navigate through the placeholders.
29+
30+
**Example:**
31+
32+
1. Type `sqlcone` in a `.sql` file.
33+
2. Press `Tab`.
34+
3. The following snippet will be inserted:
35+
```sql
36+
-- name: GetUser :one
37+
SELECT * FROM users
38+
WHERE id = $1;
39+
```
40+
4. `GetUser` will be selected. Type your desired query name, then press `Tab` to move to `users`, and so on.
41+
42+
## Available Snippets
43+
44+
Here's a categorized list of the main snippets included:
45+
46+
### SQLC Core Templates
47+
48+
| Prefix | Description |
49+
| :--------- | :-------------------------------- |
50+
| `sqlcone` | Get single row by ID |
51+
| `sqlcmany` | Get paginated results |
52+
| `sqlcinsert`| Insert with returning columns |
53+
| `sqlcupdate`| Update record |
54+
| `sqlcdelete`| Delete record |
55+
| `sqlcbatch`| Batch insert operation |
56+
57+
### SQLC Advanced Patterns
58+
59+
| Prefix | Description |
60+
| :--------- | :-------------------------------- |
61+
| `sqlcjoin` | Join with aggregation |
62+
| `sqlcjson` | Query JSONB field |
63+
| `sqlcarray`| Query array column |
64+
| `sqlcfts` | Full-text search query |
65+
| `sqlctx` | Transaction block |
66+
67+
### SQLC v2 Features
68+
69+
| Prefix | Description |
70+
| :------------ | :--------------------------------- |
71+
| `sqlcv2` | sqlc v2 named parameters |
72+
| `sqlcv2batch` | sqlc v2 batch with returning |
73+
| `sqlcv2type` | sqlc v2 with custom types |
74+
75+
### PostgreSQL DDL (Data Definition Language)
76+
77+
| Prefix | Description |
78+
| :---------- | :-------------------------------- |
79+
| `pgtbl` | Create table with audit columns |
80+
| `pgidx` | Create index |
81+
| `pgenum` | Create enum type |
82+
| `pgfunc` | Create PL/pgSQL function |
83+
| `pgtrigger` | Auto-update timestamp trigger |
84+
85+
### PostgreSQL Advanced DML & Queries
86+
87+
| Prefix | Description |
88+
| :------------ | :-------------------------------- |
89+
| `pgcte` | Common Table Expression |
90+
| `pgjsonb` | JSONB column with default |
91+
| `pgarray` | Text array column |
92+
| `pgfts` | Full-text search setup |
93+
| `pguuid` | Generate UUID v4 (`gen_random_uuid()`) |
94+
95+
### SQLC Configuration & Comments
96+
97+
| Prefix | Description |
98+
| :----------- | :-------------------------------- |
99+
| `sqlcconfig` | sqlc configuration template (`sqlc.yaml`) |
100+
| `sqlcmodel` | Add comments for sqlc model |
101+
102+
### Migration Utilities
103+
104+
| Prefix | Description |
105+
| :--------- | :-------------------------------- |
106+
| `pgext` | Create PostgreSQL extension |
107+
| `pgaddcol` | Add column to table |
108+
| `pgdropcol`| Drop column from table |
109+
110+
### Security
111+
112+
| Prefix | Description |
113+
| :-------- | :-------------------------------- |
114+
| `pgrls` | Row Level Security policy |
115+
| `pggrant` | Grant table permissions |
116+
117+
### Performance & Indexing
118+
119+
| Prefix | Description |
120+
| :------------- | :-------------------------------- |
121+
| `pgexpridx` | Create index on expression |
122+
| `pgpartialidx` | Create partial index |
123+
124+
### Utility & Testing Snippets
125+
126+
| Prefix | Description |
127+
| :------------ | :-------------------------------- |
128+
| `pgexplain` | Detailed query analysis (`EXPLAIN ANALYZE BUFFERS VERBOSE`) |
129+
| `pgnow` | Current timestamp (`NOW()`) |
130+
| `pginterval` | Time interval |
131+
| `pgjsonbuild` | Build JSONB object |
132+
| `pgarrayagg` | Aggregate to array |
133+
| `pgbegin` | Test transaction block (BEGIN/ROLLBACK) |
134+
135+
*(Note: The `pgexplain` prefix from the `TESTING` section is listed above due to its comprehensiveness. The original JSON has two `pgexplain` entries; this one includes `VERBOSE`.)*
136+
137+
138+
## Why These Snippets?
139+
140+
* **Reduce Syntax Errors**: Pre-defined structures minimize typos and syntax mistakes.
141+
* **Enforce Best Practices**: Snippets incorporate common patterns like audit columns, proper indexing, and SQLC naming conventions.
142+
* **Accelerate Development**: Spend less time writing boilerplate and more time on business logic.
143+
* **Full SQLC Compatibility**: Designed to work seamlessly with SQLC's query parsing and code generation.
144+
145+
146+
## Contributing
147+
148+
Contributions are welcome! If you have a snippet that you think would be a great addition, or if you have improvements for existing ones:
149+
150+
1. Fork the repository.
151+
2. Create a new branch (`git checkout -b feature/your-feature-name`).
152+
3. Add or modify snippets in the `snippets/snippets.json` file (or wherever the source JSON is kept).
153+
4. Commit your changes (`git commit -am 'Add some feature'`).
154+
5. Push to the branch (`git push origin feature/your-feature-name`).
155+
6. Create a new Pull Request.
156+
157+
Please ensure your snippets are well-formatted, include a clear `prefix` and `description`, and use placeholders effectively.
158+
159+
## License
160+
161+
MIT License.

eslint.config.mjs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import globals from "globals";
2+
3+
export default [{
4+
files: ["**/*.js"],
5+
languageOptions: {
6+
globals: {
7+
...globals.commonjs,
8+
...globals.node,
9+
...globals.mocha,
10+
},
11+
12+
ecmaVersion: 2022,
13+
sourceType: "module",
14+
},
15+
16+
rules: {
17+
"no-const-assign": "warn",
18+
"no-this-before-super": "warn",
19+
"no-undef": "warn",
20+
"no-unreachable": "warn",
21+
"no-unused-vars": "warn",
22+
"constructor-super": "warn",
23+
"valid-typeof": "warn",
24+
},
25+
}];

extension.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// The module 'vscode' contains the VS Code extensibility API
2+
// Import the module and reference it with the alias vscode in your code below
3+
const vscode = require('vscode');
4+
5+
// This method is called when your extension is activated
6+
// Your extension is activated the very first time the command is executed
7+
8+
/**
9+
* @param {vscode.ExtensionContext} context
10+
*/
11+
function activate(context) {
12+
13+
// Use the console to output diagnostic information (console.log) and errors (console.error)
14+
// This line of code will only be executed once when your extension is activated
15+
console.log('Congratulations, your extension "sqlc-snippets" is now active!');
16+
17+
// The command has been defined in the package.json file
18+
// Now provide the implementation of the command with registerCommand
19+
// The commandId parameter must match the command field in package.json
20+
const disposable = vscode.commands.registerCommand('sqlc-snippets.helloWorld', function () {
21+
// The code you place here will be executed every time your command is executed
22+
23+
// Display a message box to the user
24+
vscode.window.showInformationMessage('Hello World from sqlc-sniffets!');
25+
});
26+
27+
context.subscriptions.push(disposable);
28+
}
29+
30+
// This method is called when your extension is deactivated
31+
function deactivate() {}
32+
33+
module.exports = {
34+
activate,
35+
deactivate
36+
}

images/icon.png

68.6 KB
Loading

0 commit comments

Comments
 (0)