Skip to content

Commit

Permalink
Docs: Update the utils docs
Browse files Browse the repository at this point in the history
  • Loading branch information
raycastbot committed Oct 11, 2024
1 parent 844e102 commit f8fea15
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/utils-reference/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- [runAppleScript](utils-reference/functions/runAppleScript.md)
- [showFailureToast](utils-reference/functions/showFailureToast.md)
- [createDeeplink](utils-reference/functions/createDeeplink.md)
- [executeSQL](utils-reference/functions/executeSQL.md)
- [Icons](utils-reference/icons/README.md)
- [getAvatarIcon](utils-reference/icons/getAvatarIcon.md)
- [getFavicon](utils-reference/icons/getFavicon.md)
Expand Down
46 changes: 46 additions & 0 deletions docs/utils-reference/functions/executeSQL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# `executeSQL`

A function that executes a SQL query on a local SQLite database and returns the query result in JSON format.

## Signature

```ts
function executeSQL<T = unknown>(databasePath: string, query: string): Promise<T[]>
```

### Arguments

- `databasePath` is the path to the local SQL database.
- `query` is the SQL query to run on the database.

### Return

Returns a `Promise` that resolves to an array of objects representing the query results.

## Example

```typescript
import { closeMainWindow, Clipboard } from "@raycast/api";
import { executeSQL } from "@raycast/utils";
type Message = { body: string; code: string };
const DB_PATH = "/path/to/chat.db";
export default async function Command() {
const query = `
SELECT body, code
FROM message
ORDER BY date DESC
LIMIT 1;
`;
const messages = await executeSQL<Message>(DB_PATH, query);
if (messages.length > 0) {
const latestCode = messages[0].code;
await Clipboard.paste(latestCode);
await closeMainWindow();
}
}
```
4 changes: 4 additions & 0 deletions docs/utils-reference/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ npm install --save @raycast/utils

## Changelog

### v1.18.0

- Add a new [`executeSQL](./functions/executeSQL.md) function.

### v1.17.0

- Add a new [`createDeeplink`](./functions/createDeeplink.md) function.
Expand Down

0 comments on commit f8fea15

Please sign in to comment.