Skip to content

Commit

Permalink
feat: initial release
Browse files Browse the repository at this point in the history
  • Loading branch information
notrab committed May 5, 2024
0 parents commit 7fa3c67
Show file tree
Hide file tree
Showing 12 changed files with 4,609 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release

on:
push:
branches:
- main

permissions:
contents: write
issues: write
pull-requests: write

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: 8
- uses: actions/setup-node@v4
with:
node-version: "lts/*"
cache: "pnpm"
- run: pnpm install
- run: pnpm build
- run: pnpm test
- run: pnpm audit signatures
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npx semantic-release
21 changes: 21 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
on:
pull_request:
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup pnpm
uses: pnpm/action-setup@v3
with:
version: 8
- uses: actions/setup-node@v4
with:
node-version: "lts/*"
cache: "pnpm"
- run: pnpm install
- run: pnpm build
- run: pnpm test -r
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
dev.db
205 changes: 205 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
# sqlite-statement-type

This is a set of functions that let you test is the SQLite statement is a certain operation.

This is useful when you want to know if a statement is a SELECT, INSERT, UPDATE, DELETE, CREATE TABLE, etc.

**The next steps for this library would be to add support for checking recursive statements.**

## Install

```bash
npm install sqlite-statement-type
```

## Quickstart

```ts
import { isSelect } from "sqlite-statement-type";

const statement = "SELECT * FROM users";

console.log(isSelect(statement)); // true
```

## API Reference

### `isSelect`

```ts
import { isSelect } from "sqlite-statement-type";

const statement = "SELECT * FROM table";

const result = isSelect(statement);
```

### `isInsert`

```ts
import { isInsert } from "sqlite-statement-type";

const statement = "INSERT INTO table (column) VALUES ('value')";

const result = isInsert(statement);
```

### `isUpdate`

```ts
import { isUpdate } from "sqlite-statement-type";

const statement = "UPDATE table SET column = 'value'";

const result = isUpdate(statement);
```

### `isDelete`

```ts
import { isDelete } from "sqlite-statement-type";

const statement = "DELETE FROM table";

const result = isDelete(statement);
```

### `isCreateTable`

```ts
import { isCreateTable } from "sqlite-statement-type";

const statement = "CREATE TABLE table (column TEXT)";

const result = isCreateTable(statement);
```

### `isAlterTable`

```ts
import { isAlterTable } from "sqlite-statement-type";

const statement = "ALTER TABLE table ADD COLUMN column TEXT";

const result = isAlterTable(statement);
```

### `isDropTable`

```ts
import { isDropTable } from "sqlite-statement-type";

const statement = "DROP TABLE table";

const result = isDropTable(statement);
```

### `isCreateIndex`

```ts
import { isCreateIndex } from "sqlite-statement-type";

const statement = "CREATE INDEX index ON table (column)";

const result = isCreateIndex(statement);
```

### `isDropIndex`

```ts
import { isDropIndex } from "sqlite-statement-type";

const statement = "DROP INDEX index";

const result = isDropIndex(statement);
```

### `isCreateView`

```ts
import { isCreateView } from "sqlite-statement-type";

const statement = "CREATE VIEW view AS SELECT * FROM table";

const result = isCreateView(statement);
```

### `isAlterView`

```ts
import { isAlterView } from "sqlite-statement-type";

const statement = "ALTER VIEW view AS SELECT * FROM table";

const result = isAlterView(statement);
```

### `isDropView`

```ts
import { isDropView } from "sqlite-statement-type";

const statement = "DROP VIEW view";

const result = isDropView(statement);
```

### `isPragma`

```ts
import { isPragma } from "sqlite-statement-type";

const statement = "PRAGMA table_info(table)";

const result = isPragma(statement);
```

### `isBeginTransaction`

```ts
import { isBeginTransaction } from "sqlite-statement-type";

const statement = "BEGIN TRANSACTION";

const result = isBeginTransaction(statement);
```

### `isAttach`

```ts
import { isAttach } from "sqlite-statement-type";

const statement = "ATTACH DATABASE 'file.db' AS db";

const result = isAttach(statement);
```

### `isDetach`

```ts
import { isDetach } from "sqlite-statement-type";

const statement = "DETACH DATABASE db";

const result = isDetach(statement);
```

### `isCreateTrigger`

```ts
import { isCreateTrigger } from "sqlite-statement-type";

const statement = "CREATE TRIGGER trigger AFTER INSERT ON table BEGIN END";

const result = isCreateTrigger(statement);
```

### `isDropTrigger`

```ts
import { isDropTrigger } from "sqlite-statement-type";

const statement = "DROP TRIGGER trigger";

const result = isDropTrigger(statement);
```
67 changes: 67 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"name": "sqlite-statement-type",
"version": "0.0.0-development",
"description": "Check what type of statement a SQL query is.",
"keywords": [
"sqlite",
"sql"
],
"author": "Jamie Barton <jamie@notrab.dev> (https://notrab.dev)",
"license": "MIT",
"repository": "notrab/sqlite-statement-type",
"scripts": {
"build": "tsup",
"dev": "tsup --watch --clean=false",
"test": "vitest",
"test:watch": "vitest watch",
"semantic-release": "semantic-release"
},
"tsup": {
"entry": [
"src/index.ts"
],
"splitting": true,
"sourcemap": true,
"clean": true,
"dts": true,
"format": [
"esm",
"cjs"
],
"skipNodeModulesBundle": true,
"externals": [
"node_modules"
]
},
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": {
"node": "./dist/index.js",
"default": "./dist/index.js"
},
"require": {
"node": "./dist/index.cjs",
"default": "./dist/index.cjs"
}
}
},
"files": [
"dist",
"README.md"
],
"publishConfig": {
"access": "public"
},
"devDependencies": {
"semantic-release": "^23.0.8",
"tsup": "^8.0.2",
"typescript": "^5.4.5",
"vite": "^5.2.11",
"vitest": "^1.6.0"
}
}
Loading

0 comments on commit 7fa3c67

Please sign in to comment.