-
Notifications
You must be signed in to change notification settings - Fork 0
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
1b60af7
commit 218770c
Showing
16 changed files
with
189 additions
and
8 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
prisma/migrations/20231209142417_tool_update_date/migration.sql
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,17 @@ | ||
-- RedefineTables | ||
PRAGMA foreign_keys=OFF; | ||
CREATE TABLE "new_Tool" ( | ||
"name" TEXT NOT NULL PRIMARY KEY, | ||
"created" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updated" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"lastUsed" DATETIME, | ||
"query" TEXT NOT NULL, | ||
"description" TEXT, | ||
"count" INTEGER NOT NULL DEFAULT 0 | ||
); | ||
INSERT INTO "new_Tool" ("count", "created", "description", "lastUsed", "name", "query") SELECT "count", "created", "description", "lastUsed", "name", "query" FROM "Tool"; | ||
DROP TABLE "Tool"; | ||
ALTER TABLE "new_Tool" RENAME TO "Tool"; | ||
CREATE UNIQUE INDEX "Tool_name_key" ON "Tool"("name"); | ||
PRAGMA foreign_key_check; | ||
PRAGMA foreign_keys=ON; |
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
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
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
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
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
File renamed without changes.
File renamed without changes.
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,40 @@ | ||
import {Args, Command, Flags, ux} from '@oclif/core' | ||
import {PrismaClient} from '@prisma/client' | ||
import {format, printFormatted} from '../../output.js' | ||
import {sqlqdb} from '../../database.js' | ||
import {AppCommand} from '../../AppCommand.js' | ||
|
||
export default class Get extends AppCommand { | ||
static args = { | ||
name: Args.string({description: 'Name of tool', required: true}), | ||
} | ||
|
||
static description = 'Get a tool' | ||
|
||
static examples = [] | ||
|
||
static flags = { | ||
format, | ||
} | ||
|
||
async run(): Promise<any> { | ||
const {flags, args} = await this.parse(Get) | ||
const {name} = args | ||
const {format} = flags | ||
|
||
const result = await this.load( | ||
'Searching', | ||
this.db.tool.findFirst({ | ||
where: { | ||
name, | ||
}, | ||
}), | ||
) | ||
|
||
if (!result) { | ||
ux.error(`Tool with name '${name}' not found`) | ||
} | ||
|
||
printFormatted(format, result) | ||
} | ||
} |
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,54 @@ | ||
import {Args, Command, Flags, ux} from '@oclif/core' | ||
import {PrismaClient} from '@prisma/client' | ||
import {format, printFormatted} from '../../output.js' | ||
import {sqlqdb} from '../../database.js' | ||
import {AppCommand} from '../../AppCommand.js' | ||
|
||
export default class List extends AppCommand { | ||
static args = { | ||
search: Args.string({description: 'Part of a query to search for', required: false}), | ||
} | ||
|
||
static aliases = ['tool:ls'] | ||
|
||
static description = 'Search tools' | ||
|
||
static examples = [] | ||
|
||
static flags = { | ||
format, | ||
count: Flags.integer({description: 'Maximum number of results to return', required: false, default: 20}), | ||
} | ||
|
||
async run(): Promise<any> { | ||
const {flags, args} = await this.parse(List) | ||
const {search = ''} = args | ||
const {count, format} = flags | ||
|
||
const result = await this.load( | ||
'Searching', | ||
this.db.tool.findMany({ | ||
take: count, | ||
orderBy: { | ||
lastUsed: 'desc', | ||
}, | ||
where: { | ||
OR: [ | ||
{ | ||
query: { | ||
contains: search, | ||
}, | ||
}, | ||
{ | ||
description: { | ||
contains: search, | ||
}, | ||
}, | ||
], | ||
}, | ||
}), | ||
) | ||
|
||
printFormatted(format, result) | ||
} | ||
} |
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,47 @@ | ||
import {Args, Command, Flags, ux} from '@oclif/core' | ||
import {PrismaClient} from '@prisma/client' | ||
import {format, printFormatted} from '../../output.js' | ||
import {sqlqdb} from '../../database.js' | ||
import {AppCommand} from '../../AppCommand.js' | ||
|
||
export default class Create extends AppCommand { | ||
static args = { | ||
name: Args.string({description: 'Name for the tool', required: true}), | ||
query: Args.string({ | ||
description: | ||
'A query that the tool will run. This may contain parameters in the format of $Index that will be evaluated when the query runs', | ||
required: false, | ||
}), | ||
description: Args.string({ | ||
description: 'Description for the tool', | ||
required: false, | ||
}), | ||
} | ||
|
||
static description = 'Update a tool' | ||
|
||
static examples = [] | ||
|
||
static flags = { | ||
format, | ||
} | ||
|
||
async run(): Promise<any> { | ||
const {args, flags} = await this.parse(Create) | ||
const {name, query, description} = args | ||
const {format} = flags | ||
|
||
const result = await this.db.tool.update({ | ||
where: { | ||
name, | ||
}, | ||
data: { | ||
query, | ||
description, | ||
updated: new Date(), | ||
}, | ||
}) | ||
|
||
printFormatted(format, result) | ||
} | ||
} |