Skip to content

Commit e725f6d

Browse files
Play around with querying
1. Added one prompt to query for all violations
1 parent 7f05a18 commit e725f6d

File tree

4 files changed

+108
-22
lines changed

4 files changed

+108
-22
lines changed

prompts/pylint/2-make-db-schema.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ tools:
1919
---
2020

2121
# prompt user
22-
22+
2323
Write a SQL schema for a table named RANGES with columns ID, PATH, START_LINE, END_LINE, START_COLUMN, and
24-
END_COLUMN. The ID is the primary key and should be sequenced.
24+
END_COLUMN. The ID is the primary key and is a STRING type.
2525

26-
Write a SQL schema for a table named VIOLATIONS with a foreign key named RANGE, and columns
27-
MESSAGE, TYPE, and ID. The ID is the primary key.
26+
Write a SQL schema for a table named VIOLATIONS with a foreign key named RANGE of type STRING, and columns
27+
MESSAGE, TYPE, and ID. The ID is the primary key and should be sequenced.
2828

2929
Run the sqlite command with the database set to `/thread/db.dqlite` and send the SQL generated above.
3030

prompts/pylint/3-4-json-violations->sql-violations.md

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,6 @@ tools:
1212
image: vonwig/javascript-runner
1313
command:
1414
- "{{javascript|safe}}"
15-
- name: sqlite
16-
description: run the sqlite command
17-
parameters:
18-
type: object
19-
properties:
20-
database:
21-
type: string
22-
description: the path to the database
23-
sql:
24-
type: string
25-
description: the sql statement to run
26-
container:
27-
image: vonwig/sqlite:latest
28-
command:
29-
- "{{database}}"
30-
- "{{sql|safe}}"
3115
---
3216

3317
# prompt user
@@ -43,8 +27,11 @@ It should then iterate over each element of an array with the following schema:
4327
```
4428

4529
For each element of the array, it should create two INSERT statements.
46-
The first should insert the columns MESSAGE, and TYPE into a table named VIOLATIONS using the properties from the map.
47-
The second should insert the the columns PATH, START_LINE, END_LINE, START_COLUMN, END_COLUMN into a tabled named RANGE using the properties from the map.
30+
The first should insert the columns ID, PATH, START_LINE, END_LINE, START_COLUMN, END_COLUMN
31+
into a tabled named RANGES using the properties from the map. The ID column should be a random string.
32+
The second should insert the columns MESSAGE, TYPE, RANGE into a table named VIOLATIONS
33+
using the properties from the map. The RANGE column should be the ID of the previous row in the RANGES table.
34+
If any strings contain single quotes, they should be escaped.
4835

4936
The statements should be written to the file /thread/insert.sql
5037

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
tools:
3+
- name: sqlite
4+
description: run the sqlite command
5+
parameters:
6+
type: object
7+
properties:
8+
database:
9+
type: string
10+
description: the path to the database
11+
sql:
12+
type: string
13+
description: the sql statement to run
14+
container:
15+
image: vonwig/sqlite:latest
16+
command:
17+
- "{{database}}"
18+
- ".read /thread/insert.sql"
19+
---
20+
21+
# volumes
22+
23+
```sh
24+
docker run -it --rm -v thread:/thread \
25+
vonwig/bb:latest \
26+
'{}' \
27+
'(println (slurp "/thread/insert.sql"))'
28+
```
29+
30+
```
31+
docker run -it --rm -v thread:/thread \
32+
vonwig/sqlite:latest \
33+
/thread/db.dqlite \
34+
".schema RANGES"
35+
```
36+
37+
```
38+
docker run -it --rm -v thread:/thread \
39+
vonwig/sqlite:latest \
40+
/thread/db.dqlite \
41+
".schema VIOLATIONS"
42+
```
43+
44+
```
45+
docker run -it --rm -v thread:/thread \
46+
vonwig/sqlite:latest \
47+
/thread/db.dqlite \
48+
".open /thread/insert.sql"
49+
```
50+
51+
```
52+
docker run -it --rm -v thread:/thread \
53+
vonwig/sqlite:latest \
54+
/thread/db.dqlite \
55+
"SELECT * FROM VIOLATIONS INNER JOIN RANGES ON VIOLATIONS.RANGE = RANGES.ID WHERE RANGES.PATH = 'src/app.py'"
56+
```
57+
58+
```
59+
docker run -it --rm -v thread:/thread \
60+
vonwig/sqlite:latest \
61+
/thread/db.dqlite \
62+
"SELECT * FROM RANGES WHERE RANGES.PATH = 'src/app.py'"
63+
```
64+
65+
66+
# prompt user
67+
68+
Run the sqlite command with the path to the database set to `/thread/db.dqlite`.
69+

prompts/pylint/6-1-query.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
tools:
3+
- name: sqlite
4+
description: run the sqlite command
5+
parameters:
6+
type: object
7+
properties:
8+
database:
9+
type: string
10+
description: the path to the database
11+
sql:
12+
type: string
13+
description: the sql statement to run
14+
container:
15+
image: vonwig/sqlite:latest
16+
command:
17+
- "{{database}}"
18+
- "{{sql|safe}}"
19+
---
20+
21+
# prompt user
22+
23+
Given this schema:
24+
25+
```sql
26+
CREATE TABLE VIOLATIONS (ID INTEGER PRIMARY KEY AUTOINCREMENT, MESSAGE TEXT, TYPE TEXT, RANGE STRING, FOREIGN KEY (RANGE) REFERENCES RANGES (ID));
27+
CREATE TABLE RANGES (ID STRING PRIMARY KEY, PATH TEXT, START_LINE INT, END_LINE INT, START_COLUMN INT, END_COLUMN INT);
28+
```
29+
30+
Generate a query to find all the violations in the file `src/app.py` and then run the sqlite command on database `/thread/db.dqlite`.

0 commit comments

Comments
 (0)