Skip to content

Commit dcfcc78

Browse files
author
Gert Marginet
committed
Initial commit
1 parent 74f6d60 commit dcfcc78

31 files changed

+1166
-1
lines changed

README.md

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,68 @@
1-
# SqlQueryTools
1+
# SqlQueryTools
2+
3+
SqlQueryTools is a visual studio extension that generates code behind files for sql files.
4+
The code behinde file contains a static class with the same name as the sql file.
5+
That class has a const called query, with the content of the sql file.
6+
It also contains a const for every parameter that is declared in the sql file.
7+
8+
Before SqlQueryTools start generating the code behind file it validates the content of the sql file with a SQL Server database.
9+
10+
The generated code can be used to execute the query with an ORM like [Dapper](https://github.com/DapperLib/Dapper)
11+
12+
### Download
13+
14+
Download from [releases](https://github.com/gmarginet/SqlQueryTools/releases)
15+
16+
### Getting started
17+
18+
You can add a new sql file by right clicking on a .cs file and select 'Sql Query Tools/Add Sql File'.
19+
This will add a nested sql file below the selected csharp file.
20+
21+
![image](https://github.com/gmarginet/SqlQueryTools/blob/master/art/AddSqlFile.png)
22+
23+
The following dialog will pop up, enter the filename and click 'Add file'.
24+
25+
![image](https://github.com/gmarginet/SqlQueryTools/blob/master/art/AddNewSqlFileDialog.png)
26+
27+
The added sql file will have the following content.
28+
29+
![image](https://github.com/gmarginet/SqlQueryTools/blob/master/art/SqlFileDefaultContent.png)
30+
31+
Before you start writing your query you should set the SQL server connection string that Sql Query Tools should use to validate the query.
32+
The connection string can be set in the .csproj file you just added the sql file to.
33+
34+
![image](https://github.com/gmarginet/SqlQueryTools/blob/master/art/ConnectionString.png)
35+
36+
Now you can start writing your sql query.
37+
You can remove all comments but if you use parameters in your query you should put the parameter declarations above the 'End Of Parameter Declaration' marker.
38+
And your actual query below the marker.
39+
The generated const string will only contain the lines below the marker, if the sql file doesn't contain a marker line all lines will be put in the const string.
40+
41+
All comments that you keep in your sql file will not be put in the const string.
42+
43+
Below you can find an example of a query.
44+
45+
![image](https://github.com/gmarginet/SqlQueryTools/blob/master/art/ExampleSql.png)
46+
47+
When you save the sql file, Sql Query Tools will start generating the code behind.
48+
The progress can be found in the Sql Query Tools output panel.
49+
Here you will also find more info when something went wrong.
50+
51+
![image](https://github.com/gmarginet/SqlQueryTools/blob/master/art/OutputPanel.png)
52+
53+
And the generated code for the example query from above will look like this.
54+
55+
![image](https://github.com/gmarginet/SqlQueryTools/blob/master/art/ExampleCode.png)
56+
57+
The solution explorer will now look like this.
58+
59+
![image](https://github.com/gmarginet/SqlQueryTools/blob/master/art/SolutionExplorer.png)
60+
61+
If you don't like the file suffixes or the parameter declaration marker.
62+
These can be changed via 'Tools/Options/SqlQueryTools
63+
64+
![image](https://github.com/gmarginet/SqlQueryTools/blob/master/art/Options.png)
65+
66+
### License
67+
68+
MIT

art/AddNewSqlFileDialog.png

6.4 KB
Loading

art/AddSqlFile.png

20.6 KB
Loading

art/ConnectionString.png

35.5 KB
Loading

art/ExampleCode.png

29.7 KB
Loading

art/ExampleSql.png

15.1 KB
Loading

art/Options.png

18.1 KB
Loading

art/OutputPanel.png

4.82 KB
Loading

art/SolutionExplorer.png

9.08 KB
Loading

art/SqlFileDefaultContent.png

10.1 KB
Loading

0 commit comments

Comments
 (0)