Skip to content

Commit b0feb08

Browse files
committed
Include README for usage examples
1 parent 3265904 commit b0feb08

1 file changed

Lines changed: 59 additions & 0 deletions

File tree

plugins/sql-macros/README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# SQL Macros Plugin
2+
3+
The SQL Macros Plugin for Starbase provides SQL query validation and enhancement features to improve code quality and prevent common SQL anti-patterns.
4+
5+
## Installation
6+
7+
```bash
8+
npm install @starbase/sql-macros-plugin
9+
```
10+
11+
## Usage
12+
13+
Add the SqlMacros plugin to your Starbase configuration:
14+
15+
```typescript
16+
import { SqlMacros } from './plugins/sql-macros-plugin'
17+
const plugins = [
18+
// ... other plugins
19+
new SqlMacros({
20+
preventSelectStar: true,
21+
}),
22+
] satisfies StarbasePlugin[]
23+
```
24+
25+
## Configuration Options
26+
27+
| Option | Type | Default | Description |
28+
| ------------------- | ------- | ------- | ---------------------------------------------------------------------------------------------- |
29+
| `preventSelectStar` | boolean | `false` | When enabled, prevents the use of `SELECT *` in queries to encourage explicit column selection |
30+
31+
## Features
32+
33+
### Prevent SELECT \*
34+
35+
When `preventSelectStar` is enabled, the plugin will raise an error if it encounters a `SELECT *` in your SQL queries. This encourages better practices by requiring explicit column selection.
36+
37+
Example of invalid query:
38+
39+
```sql
40+
SELECT * FROM users; // Will raise an error
41+
```
42+
43+
Example of valid query:
44+
45+
```sql
46+
SELECT id, username, email FROM users; // Correct usage
47+
```
48+
49+
### Exclude Columns with `$_exclude`
50+
51+
The `$_exclude` macro allows you to select all columns except the specified ones. This is useful when you want to avoid listing all columns explicitly except a few.
52+
53+
Example usage:
54+
55+
```sql
56+
SELECT $_exclude(password, secret_key) FROM users;
57+
```
58+
59+
In this example, all columns from the `users` table will be selected except for `password` and `secret_key`.

0 commit comments

Comments
 (0)