Skip to content

Commit 83b2738

Browse files
committed
Made it so SQL inside Python gets automatically detected & highlighted!
1 parent be9327e commit 83b2738

15 files changed

Lines changed: 131 additions & 216 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
.DS_Store
12
node_modules

CHANGELOG.md

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog] (http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
55

6-
### [1.1.0] - 2019-06-04
7-
- Added support for f-strings
8-
9-
### [1.0.0] - 2019-03-29
10-
- Added snippet and keybinding
11-
12-
### [0.1.0] - 2019-03-28
13-
- Published on VS Code marketplace
14-
15-
## [0.0.1] - 2018-03-28
16-
### Added
17-
- First working version
6+
### [0.0.1] - 2021-12-13
7+
- Made it so adding `--(begin-)?sql` and `--end-sql` is not necessary!
8+
- Forked from es6-string-html

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 ptweir
3+
Copyright (c) 2018 ptweir, munro
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,16 @@
1-
# SQL highlighting in Python multiline strings for VS Code
1+
# SQL highlighting in Python multiline strings for VS Code
22

3-
Adds syntax highlight support for python multiline SQL strings in VS Code.
3+
Adds automatic syntax highlight support SQL strings embedded in Python strings.
44

5-
## Installation
5+
**This is still under development,** if you experience issues please try to help us fix them. :) Auto detecting SQL, and highlighting it properly insight Python is _hard_!
66

7-
Install `python-string-sql` from extensions (`ctrl + shift + x` or `cmd + shift + x` on mac).
8-
> Also available on [marketplace.visualstudio.com](https://marketplace.visualstudio.com/items?itemName=ptweir.python-string-sql)
9-
10-
## Example
11-
12-
[![Example](docs/demo.png)](docs/demo.py)
13-
14-
## Usage
15-
16-
Insert `--sql`, `--beginsql`, or `--begin-sql` at the beginning of the part of the string you would like highlighted and a semicolon, `--endsql`, or `--end-sql` at the end of the highlighted section.
17-
18-
### Snippets
19-
begin typing `sql` and the autocomplete snippet will appear:
20-
21-
![Snippet](docs/snippet.gif)
22-
23-
### Keybindings
24-
25-
cmd+s (or ctrl+s on mac) - Insert the following snippet:
26-
```
27-
"""
28-
--sql
29-
SELECT
30-
;
31-
"""
32-
```
33-
34-
## Requirements
35-
36-
- Visual Studio Code v1.32.0 recommended
37-
- Comments at beginning and end of highlighted section in the string (see Usage section).
7+
![Image showing syntax highlighting working for SQL embedded inside a Python string](docs/demo.png)
388

399
## Community
40-
- 2018-09-04 forked from [es6-string-css](https://github.com/bashmish/es6-string-css)
10+
- 2021-12-13 forked from [python-string-sql](https://github.com/ptweir/python-string-sql)
4111

4212
## Release Notes
4313

44-
### [1.1.0] - 2019-06-04
45-
- Added support for f-strings
46-
47-
### [1.0.0] - 2019-03-29
48-
- Added snippet and keybinding
49-
50-
### [0.1.0] - 2019-03-28
51-
- Published on VS Code marketplace
52-
53-
### [0.0.1] - 2019-03-28
54-
- Got it working based on [these instructions](https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide)
55-
56-
### [0.0.0] - 2018-09-04
14+
### [0.0.1] - 2021-12-13
15+
- Made it so adding `--(begin-)?sql` and `--end-sql` is not necessary!
5716
- Forked from es6-string-html
58-
173 KB
Binary file not shown.

docs/demo.png

42.3 KB
Loading

docs/demo.py

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,47 @@
1-
import psycopg2
2-
3-
conn = psycopg2.connect("dbname=test user=postgres")
4-
cur = conn.cursor()
5-
6-
query = """
7-
--begin-sql
8-
SELECT last_name,
9-
start_day,
10-
COUNT(*) AS num_entries
11-
FROM schema.table -- great name!
12-
WHERE start_day >= '2019-01-01'
13-
GROUP BY last_name, start_day
14-
ORDER BY num_entries DESC
15-
LIMIT 10;
16-
"""
17-
18-
cur.execute(query)
19-
first_row = cur.fetchone()
1+
import sqlite3
2+
3+
DATASET = [
4+
("Tencho", "2018-12-03"),
5+
("Bessho", "2018-12-03"),
6+
("Emoto", "2020-12-03"),
7+
("Gamo", "2020-12-03"),
8+
("Funakoshi", "2020-12-03"),
9+
("Funakoshi", "2020-12-03"),
10+
("Doigaki", "2020-12-03"),
11+
("Doigaki", "2020-20-03"),
12+
("Chikura", "2020-12-03"),
13+
("Akabane", "2020-12-03"),
14+
]
15+
16+
17+
def main():
18+
conn = sqlite3.connect(":memory:")
19+
20+
conn.executescript(
21+
"""
22+
DROP TABLE IF EXISTS foobar;
23+
CREATE TABLE foobar (
24+
last_name TEXT TEXT NOT NULL,
25+
start_day TEXT NOT NULL
26+
);
27+
"""
28+
)
29+
30+
conn.executemany("INSERT INTO foobar VALUES (?, ?)", DATASET)
31+
32+
query = """
33+
SELECT last_name,
34+
start_day,
35+
COUNT(*) AS num_entries
36+
FROM foobar
37+
WHERE start_day >= '2019-01-01'
38+
GROUP BY last_name, start_day
39+
ORDER BY num_entries DESC
40+
LIMIT 10;
41+
"""
42+
43+
print(conn.execute(query).fetchall())
44+
45+
46+
if __name__ == "__main__":
47+
main()

docs/python-string-sql-1.1.0.vsix

-220 KB
Binary file not shown.

docs/snippet.gif

-290 KB
Binary file not shown.

package-lock.json

Lines changed: 13 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)