|
1 | 1 | # KeelMatrix.QueryWatch |
2 | 2 |
|
3 | | -[](https://github.com/OWNER/REPO/actions/workflows/ci.yml) [](https://www.nuget.org/packages/KeelMatrix.QueryWatch/) |
4 | | - |
5 | | -**For developers building tools and libraries, `KeelMatrix.QueryWatch` delivers a working NuGet package in minutes without the usual boilerplate.** |
6 | | - |
7 | | -This repository is a template that bundles together a library project, an xUnit test project, a sample console application, common build configuration, GitHub workflows, licensing and telemetry stubs, and a full suite of documentation. It allows you to start publishing high‑quality NuGet packages with minimal effort. |
| 3 | +> Catch N+1 queries and slow SQL in tests. Fail builds when query budgets are exceeded. |
8 | 4 |
|
9 | | -## Getting started |
10 | | - |
11 | | -1. Clone or download this template. |
12 | | -2. Rename the solution and default project names when prompted to match your package name. |
13 | | -3. Open the solution in Visual Studio 2022 or run `dotnet build` from the command line. |
| 5 | +[](https://github.com/OWNER/REPO/actions/workflows/ci.yml) [](https://www.nuget.org/packages/KeelMatrix.QueryWatch/) |
14 | 6 |
|
15 | | -### Install from NuGet |
| 7 | +## Install |
16 | 8 |
|
17 | 9 | ```bash |
18 | 10 | dotnet add package KeelMatrix.QueryWatch |
19 | 11 | ``` |
20 | 12 |
|
21 | | -### Quickstart |
| 13 | +## 5‑minute success (with JSON for CI) |
22 | 14 |
|
23 | | -Here's how to use the sample API exposed by the template: |
| 15 | +**Per‑test scope → export JSON:** |
24 | 16 |
|
25 | 17 | ```csharp |
26 | | -using KeelMatrix.QueryWatch; |
| 18 | +using KeelMatrix.QueryWatch.Testing; |
27 | 19 |
|
28 | | -var hello = new Hello(); |
29 | | -Console.WriteLine(hello.Greet("World")); |
30 | | -``` |
31 | | - |
32 | | -You can also explore the sample console application by running: |
| 20 | +// JSON is written even if assertions fail (helps CI). |
| 21 | +using var q = QueryWatchScope.Start( |
| 22 | + maxQueries: 5, |
| 23 | + maxAverage: TimeSpan.FromMilliseconds(50), |
| 24 | + exportJsonPath: "artifacts/qwatch.report.json"); |
33 | 25 |
|
34 | | -```bash |
35 | | -cd samples/KeelMatrix.QueryWatch.Sample |
36 | | -dotnet run |
| 26 | +// wire EF Core or ADO to q.Session, run your code... |
37 | 27 | ``` |
38 | 28 |
|
39 | | -## Target frameworks |
40 | | - |
41 | | -This package targets the following frameworks: |
42 | | - |
43 | | -* `net8.0` – for modern .NET applications. |
44 | | -* `netstandard2.0` – for broad compatibility with .NET Framework and .NET Core. |
| 29 | +**Gate in CI (already wired in ci.yml):** |
45 | 30 |
|
46 | | -## Versioning and releases |
47 | | - |
48 | | -This project follows [Semantic Versioning](https://semver.org/). Breaking changes or removal of a target framework require a new major version. New features that do not break existing behavior increment the minor version. Patch versions are used for bug fixes and small improvements. Pre‑release packages use suffixes such as `-alpha`, `-beta`, or `-rc`. |
49 | | - |
50 | | -Release notes are maintained in [`CHANGELOG.md`](CHANGELOG.md). To create a new release: |
51 | | - |
52 | | -1. Update the version in the library’s `.csproj` file and add an entry in the changelog. |
53 | | -2. Commit your changes and tag the commit (for example `git tag v1.0.0`). |
54 | | -3. Push the tag. GitHub Actions will build, sign, and publish the package to nuget.org (assuming you have configured `NUGET_API_KEY` in your repository secrets). |
55 | | - |
56 | | -## Documentation |
57 | | - |
58 | | -* [`LICENSE`](LICENSE) – The license this project is released under (MIT by default). |
59 | | -* [`SECURITY.md`](SECURITY.md) – How to report security issues. |
60 | | -* [`CONTRIBUTING.md`](CONTRIBUTING.md) – Guidelines for contributors. |
61 | | -* [`CODE_OF_CONDUCT.md`](CODE_OF_CONDUCT.md) – The code of conduct for this project. |
62 | | -* [`PRIVACY.md`](PRIVACY.md) – Information about telemetry and how to disable it. |
63 | | - |
64 | | -## FAQ |
65 | | - |
66 | | -### How do I build and test the package locally? |
67 | | - |
68 | | -Run the following commands from the repository root: |
69 | | - |
70 | | -```bash |
71 | | -dotnet restore |
72 | | -dotnet build --configuration Release |
73 | | -dotnet test --configuration Release --no-build |
74 | | -dotnet pack --configuration Release --no-build --output ./artifacts/packages |
| 31 | +```pwsh |
| 32 | +dotnet run --project tools/KeelMatrix.QueryWatch.Cli -- --input artifacts/qwatch.report.json --max-queries 50 |
75 | 33 | ``` |
76 | 34 |
|
77 | | -The resulting `.nupkg` and `.snupkg` files can be found in `./artifacts/packages`. |
78 | | - |
79 | | -### How do I consume the package without publishing it to NuGet? |
80 | | - |
81 | | -Update your `NuGet.config` to add a local feed pointing at the `artifacts/packages` folder. For example: |
82 | | - |
83 | | -```xml |
84 | | -<?xml version="1.0" encoding="utf-8"?> |
85 | | -<configuration> |
86 | | - <packageSources> |
87 | | - <add key="local" value="./artifacts/packages" /> |
88 | | - <add key="nuget.org" value="https://api.nuget.org/v3/index.json" /> |
89 | | - </packageSources> |
90 | | -</configuration> |
91 | | -``` |
92 | | - |
93 | | -Then run `dotnet restore` in your consuming project. |
94 | | - |
95 | | -### How do I add paid features or telemetry? |
96 | | - |
97 | | -The template includes stub interfaces `ILicenseValidator` and `ITelemetryClient` with no‑op implementations. Replace these with your own implementations and wire them into your API as needed. See comments in the source code for guidance. |
98 | | - |
99 | | ---- |
100 | | - |
101 | | -_This README is intentionally generic. Replace the sample code and descriptive text with information relevant to your package._ |
102 | | - |
103 | | -## Why this template (promise line) |
104 | | - |
105 | | -For developers shipping .NET libraries quickly: this template gets you from **idea → publishable NuGet** in minutes, with tests, CI, SourceLink, symbols, docs, and repo hygiene baked in. |
106 | | - |
107 | | -## Supported TFMs |
108 | | - |
109 | | -- `net8.0` |
110 | | -- `netstandard2.0` |
111 | | - |
112 | | -## Release & versioning policy |
113 | | - |
114 | | -- **SemVer**: PATCH=fixed bugs, MINOR=new features (no breaking changes), MAJOR=breaking changes or dropping a TFM. |
115 | | -- Use pre-releases: `-alpha`, `-beta`, `-rc` as needed. |
116 | | -- Tag releases as `vX.Y.Z`; CI picks up tags to publish. |
117 | | -- Maintain `CHANGELOG.md` for notable changes. |
118 | | - |
119 | | -## NuGet ID & branding |
120 | | - |
121 | | -- Choose a consistent **package ID prefix** (e.g., `KeelMatrix.*`). |
122 | | -- When ready, **reserve your prefix** on nuget.org (TODO: add link). |
123 | | -- Set **Authors**, **RepositoryUrl**, **PackageProjectUrl**, **icon** in the `.csproj`. |
124 | | - |
125 | | -## CI artifacts |
126 | | - |
127 | | -CI uploads built packages to `./artifacts/packages` as workflow artifacts you can download. |
| 35 | +**EF Core:** see `src/KeelMatrix.QueryWatch/README.md` for full example. |
128 | 36 |
|
129 | | -## Licensing & monetization stubs |
| 37 | +## Why QueryWatch? |
130 | 38 |
|
131 | | -This template includes `ILicenseValidator` + `NoopLicenseValidator` and doc notes to wire a MoR (Paddle/Lemon Squeezy). Mark paid features in code and validate via your chosen MoR before enabling. Include an **offline grace** policy (e.g., 7–30 days). |
| 39 | +- **Prevents N+1 and slow queries** before they reach production. |
| 40 | +- **Lightweight**: plug into EF Core or wrap ADO/Dapper connection. |
| 41 | +- **Redaction hooks**: mask PII or noisy literals. |
| 42 | +- **CI‑friendly**: export JSON and use the CLI gate to fail PRs. |
132 | 43 |
|
133 | | -## Telemetry (optional, off by default) |
| 44 | +## JSON schema |
134 | 45 |
|
135 | | -Implements `ITelemetryClient` with a no‑op default. If you later enable telemetry, publish a clear privacy note and allow opt‑out via `TOOLNAME_NO_TELEMETRY=1`. |
| 46 | +Stable, compact summary emitted by `KeelMatrix.QueryWatch.Reporting.QueryWatchJson.ExportToFile(report, path)` with fields: |
| 47 | +`schema, startedAt, stoppedAt, totalQueries, totalDurationMs, averageDurationMs, events[]`. |
136 | 48 |
|
137 | | -## Release checklist |
| 49 | +## CLI |
138 | 50 |
|
139 | | -- [ ] Tests pass on Release configuration |
140 | | -- [ ] `dotnet pack` produces one `.nupkg` and one `.snupkg` |
141 | | -- [ ] Version bumped in the `.csproj` |
142 | | -- [ ] Tag created `vX.Y.Z` |
143 | | -- [ ] CI artifacts verified; (optional) nuget.org push succeeded |
| 51 | +- `--input` path to JSON (default `artifacts/qwatch.report.json`) |
| 52 | +- `--max-queries`, `--max-average-ms`, `--max-total-ms` |
| 53 | +- `--baseline <file>` and `--write-baseline` to store today’s good results |
144 | 54 |
|
| 55 | +## License |
145 | 56 |
|
146 | | -> **Note:** Consider adopting [Nerdbank.GitVersioning](https://github.com/dotnet/Nerdbank.GitVersioning) later for repo-driven versioning (optional; not bundled in the template). |
| 57 | +MIT. See `LICENSE`. See `PRIVACY.md` for telemetry stance (off by default). |
0 commit comments