|
1 | 1 | # Prequel |
2 | 2 |
|
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`. |
5 | 7 |
|
6 | 8 | ## Status |
7 | 9 |
|
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 | +--> |
9 | 17 |
|
10 | 18 | ## Installation |
11 | 19 |
|
12 | 20 | WIP |
| 21 | +<!-- |
| 22 | +Install [this NuGet Package](https://example.com) in your project. |
| 23 | +--> |
13 | 24 |
|
14 | 25 | ## Usage |
15 | 26 |
|
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 | +``` |
17 | 82 |
|
18 | 83 | <!-- |
19 | 84 | Copyright 2022 Jeffrey Sharp |
|
0 commit comments