Skip to content

Commit 2047a6e

Browse files
committed
Add documentation.
1 parent 9c17f30 commit 2047a6e

1 file changed

Lines changed: 69 additions & 4 deletions

File tree

README.md

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,84 @@
11
# Prequel
22

3-
Minimal SQLCMD preprocessor.
4-
Adds a 'SQLCMD mode' to your app with one line of code.
3+
Prequel is a minimal SQLCMD-compatible preprocessor.
4+
5+
Prequel adds a 'SQLCMD mode' to your app with a couple lines of code. It
6+
supports `GO`, `$(var)`, `:setvar`, and `:r`.
57

68
## Status
79

8-
WIP
10+
Nearing release.
11+
12+
<!--
13+
- **Stable:** in private use for years with no reported defect.
14+
- **Tested:** 100% code coverage by automated tests.
15+
- **Documented:** IntelliSense on everything.
16+
-->
917

1018
## Installation
1119

1220
WIP
21+
<!--
22+
Install [this NuGet Package](https://example.com) in your project.
23+
-->
1324

1425
## Usage
1526

16-
WIP
27+
SQL in, preprocessed batches out — it's as simple as that.
28+
29+
```csharp
30+
// Import the namespace
31+
using Prequel;
32+
33+
// Create a preprocessor
34+
var preprocessor = new SqlCmdPreprocessor();
35+
36+
// Optional: set some preprocessor variables
37+
preprocessor.Variables["Foo"] = "Bar";
38+
39+
// Preprocess!
40+
var batches = preprocessor.Process(sql);
41+
42+
// Do something with the batches
43+
foreach (var batch in batches)
44+
{
45+
// ...
46+
}
47+
```
48+
49+
## SQLCMD Features
50+
51+
Prequel supports a limited subset of
52+
[SQLCMD](https://docs.microsoft.com/en-us/sql/tools/sqlcmd-utility)
53+
preprocessing features.
54+
55+
### `GO` — batch separator
56+
57+
```sql
58+
SELECT * FROM Foo; -- first batch
59+
GO
60+
SELECT * FROM Bar; -- second batch
61+
```
62+
63+
### `$(var)` — preprocessor variable expansion
64+
65+
```sql
66+
SELECT $(Columns) FROM Foo;
67+
```
68+
69+
### `:setvar` — set a preprocessor variable
70+
71+
```sql
72+
:setvar Columns Name -- this works
73+
:setvar Columns "Id, Name" -- this also works
74+
```
75+
76+
### `:r` — include a file
77+
78+
```sql
79+
:r OtherFile.sql -- this works
80+
:r "Other File.sql" -- this also works
81+
```
1782

1883
<!--
1984
Copyright 2022 Jeffrey Sharp

0 commit comments

Comments
 (0)