close
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Include README for usage examples
  • Loading branch information
Brayden committed Jan 12, 2025
commit b0feb086477c5560b1371b20592b21dab2a91eed
59 changes: 59 additions & 0 deletions plugins/sql-macros/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# SQL Macros Plugin

The SQL Macros Plugin for Starbase provides SQL query validation and enhancement features to improve code quality and prevent common SQL anti-patterns.

## Installation

```bash
npm install @starbase/sql-macros-plugin
```

## Usage

Add the SqlMacros plugin to your Starbase configuration:

```typescript
import { SqlMacros } from './plugins/sql-macros-plugin'
const plugins = [
// ... other plugins
new SqlMacros({
preventSelectStar: true,
}),
] satisfies StarbasePlugin[]
```

## Configuration Options

| Option | Type | Default | Description |
| ------------------- | ------- | ------- | ---------------------------------------------------------------------------------------------- |
| `preventSelectStar` | boolean | `false` | When enabled, prevents the use of `SELECT *` in queries to encourage explicit column selection |

## Features

### Prevent SELECT \*

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.

Example of invalid query:

```sql
SELECT * FROM users; // Will raise an error
```

Example of valid query:

```sql
SELECT id, username, email FROM users; // Correct usage
```

### Exclude Columns with `$_exclude`

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.

Example usage:

```sql
SELECT $_exclude(password, secret_key) FROM users;
```

In this example, all columns from the `users` table will be selected except for `password` and `secret_key`.