-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
844e102
commit f8fea15
Showing
3 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters