-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
29 changed files
with
1,415 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require("dotenv").config(); | ||
|
||
import type { Config } from "drizzle-kit"; | ||
|
||
export default { | ||
schema: "./src/utils/schemas/db.schema.ts", | ||
out: "./migrations", | ||
dialect: "turso", | ||
dbCredentials: { | ||
url: process.env.TURSO_DATABASE_URL!, | ||
authToken: process.env.TURSO_AUTH_TOKEN, | ||
}, | ||
} satisfies Config; |
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,30 @@ | ||
-- Current sql file was generated after introspecting the database | ||
-- If you want to run this migration please uncomment this code before executing migrations | ||
/* | ||
CREATE TABLE `brianker_requests` ( | ||
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, | ||
`status` text DEFAULT 'pending' NOT NULL, | ||
`error_message` text, | ||
`input_cast` text, | ||
`brian_input_origin_wallet` text, | ||
`brian_response` text, | ||
`grok_response` text, | ||
`redis_operation_id` text, | ||
`created_at` text DEFAULT (CURRENT_TIMESTAMP), | ||
`updated_at` text DEFAULT (CURRENT_TIMESTAMP) | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE `token` ( | ||
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, | ||
`address` text NOT NULL, | ||
`name` text NOT NULL, | ||
`ticker` text NOT NULL, | ||
`requestedBy` integer NOT NULL, | ||
`image` text NOT NULL, | ||
`date_time` text NOT NULL, | ||
`created_at` text DEFAULT (CURRENT_TIMESTAMP), | ||
`updated_at` text DEFAULT (CURRENT_TIMESTAMP) | ||
); | ||
--> statement-breakpoint | ||
CREATE UNIQUE INDEX `token_address_unique` ON `token` (`address`); | ||
*/ |
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,181 @@ | ||
{ | ||
"id": "00000000-0000-0000-0000-000000000000", | ||
"prevId": "", | ||
"version": "6", | ||
"dialect": "sqlite", | ||
"tables": { | ||
"brianker_requests": { | ||
"name": "brianker_requests", | ||
"columns": { | ||
"id": { | ||
"autoincrement": true, | ||
"name": "id", | ||
"type": "integer", | ||
"primaryKey": true, | ||
"notNull": true | ||
}, | ||
"status": { | ||
"default": "'pending'", | ||
"autoincrement": false, | ||
"name": "status", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"error_message": { | ||
"autoincrement": false, | ||
"name": "error_message", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false | ||
}, | ||
"input_cast": { | ||
"autoincrement": false, | ||
"name": "input_cast", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false | ||
}, | ||
"brian_input_origin_wallet": { | ||
"autoincrement": false, | ||
"name": "brian_input_origin_wallet", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false | ||
}, | ||
"brian_response": { | ||
"autoincrement": false, | ||
"name": "brian_response", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false | ||
}, | ||
"grok_response": { | ||
"autoincrement": false, | ||
"name": "grok_response", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false | ||
}, | ||
"redis_operation_id": { | ||
"autoincrement": false, | ||
"name": "redis_operation_id", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false | ||
}, | ||
"created_at": { | ||
"default": "(CURRENT_TIMESTAMP)", | ||
"autoincrement": false, | ||
"name": "created_at", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false | ||
}, | ||
"updated_at": { | ||
"default": "(CURRENT_TIMESTAMP)", | ||
"autoincrement": false, | ||
"name": "updated_at", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false | ||
} | ||
}, | ||
"compositePrimaryKeys": {}, | ||
"indexes": {}, | ||
"foreignKeys": {}, | ||
"uniqueConstraints": {}, | ||
"checkConstraints": {} | ||
}, | ||
"token": { | ||
"name": "token", | ||
"columns": { | ||
"id": { | ||
"autoincrement": true, | ||
"name": "id", | ||
"type": "integer", | ||
"primaryKey": true, | ||
"notNull": true | ||
}, | ||
"address": { | ||
"autoincrement": false, | ||
"name": "address", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"name": { | ||
"autoincrement": false, | ||
"name": "name", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"ticker": { | ||
"autoincrement": false, | ||
"name": "ticker", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"requestedBy": { | ||
"autoincrement": false, | ||
"name": "requestedBy", | ||
"type": "integer", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"image": { | ||
"autoincrement": false, | ||
"name": "image", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"date_time": { | ||
"autoincrement": false, | ||
"name": "date_time", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true | ||
}, | ||
"created_at": { | ||
"default": "(CURRENT_TIMESTAMP)", | ||
"autoincrement": false, | ||
"name": "created_at", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false | ||
}, | ||
"updated_at": { | ||
"default": "(CURRENT_TIMESTAMP)", | ||
"autoincrement": false, | ||
"name": "updated_at", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false | ||
} | ||
}, | ||
"compositePrimaryKeys": {}, | ||
"indexes": { | ||
"token_address_unique": { | ||
"name": "token_address_unique", | ||
"columns": [ | ||
"address" | ||
], | ||
"isUnique": true | ||
} | ||
}, | ||
"foreignKeys": {}, | ||
"uniqueConstraints": {}, | ||
"checkConstraints": {} | ||
} | ||
}, | ||
"views": {}, | ||
"enums": {}, | ||
"_meta": { | ||
"schemas": {}, | ||
"tables": {}, | ||
"columns": {} | ||
} | ||
} |
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,13 @@ | ||
{ | ||
"version": "7", | ||
"dialect": "sqlite", | ||
"entries": [ | ||
{ | ||
"idx": 0, | ||
"version": "6", | ||
"when": 1732809637063, | ||
"tag": "0000_groovy_shard", | ||
"breakpoints": true | ||
} | ||
] | ||
} |
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,3 @@ | ||
import { relations } from "drizzle-orm/relations"; | ||
import { } from "./schema"; | ||
|
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,33 @@ | ||
import { sqliteTable, AnySQLiteColumn, integer, text, uniqueIndex } from "drizzle-orm/sqlite-core" | ||
import { sql } from "drizzle-orm" | ||
|
||
export const briankerRequests = sqliteTable("brianker_requests", { | ||
id: integer().primaryKey({ autoIncrement: true }).notNull(), | ||
status: text().default("pending").notNull(), | ||
errorMessage: text("error_message"), | ||
inputCast: text("input_cast"), | ||
brianInputOriginWallet: text("brian_input_origin_wallet"), | ||
brianResponse: text("brian_response"), | ||
grokResponse: text("grok_response"), | ||
redisOperationId: text("redis_operation_id"), | ||
createdAt: text("created_at").default("sql`(CURRENT_TIMESTAMP)`"), | ||
updatedAt: text("updated_at").default("sql`(CURRENT_TIMESTAMP)`"), | ||
}); | ||
|
||
export const token = sqliteTable("token", { | ||
id: integer().primaryKey({ autoIncrement: true }).notNull(), | ||
address: text().notNull(), | ||
name: text().notNull(), | ||
ticker: text().notNull(), | ||
requestedBy: integer().notNull(), | ||
image: text().notNull(), | ||
dateTime: text("date_time").notNull(), | ||
createdAt: text("created_at").default("sql`(CURRENT_TIMESTAMP)`"), | ||
updatedAt: text("updated_at").default("sql`(CURRENT_TIMESTAMP)`"), | ||
}, | ||
(table) => { | ||
return { | ||
addressUnique: uniqueIndex("token_address_unique").on(table.address), | ||
} | ||
}); | ||
|
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,59 @@ | ||
import { getTokenFromAddress } from "@/utils/db"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
export const GET = async (req: NextRequest) => { | ||
try { | ||
const url = new URL(req.url); | ||
const searchParams = new URLSearchParams(url.searchParams); | ||
|
||
const tokenAddress = searchParams.get("address"); | ||
|
||
if (!tokenAddress) { | ||
return NextResponse.json( | ||
{ | ||
status: "nok", | ||
error: { | ||
message: "Address missing", | ||
}, | ||
}, | ||
{ | ||
status: 400, | ||
statusText: "Bad Request", | ||
} | ||
); | ||
} | ||
|
||
const token = await getTokenFromAddress(tokenAddress); | ||
if (!token) { | ||
return NextResponse.json( | ||
{ | ||
status: "nok", | ||
error: { | ||
message: "Token not found", | ||
}, | ||
}, | ||
{ | ||
status: 404, | ||
statusText: "Not Found", | ||
} | ||
); | ||
} | ||
return NextResponse.json({ | ||
status: "ok", | ||
data: token, | ||
}); | ||
} catch (error) { | ||
return NextResponse.json( | ||
{ | ||
status: "nok", | ||
error: { | ||
message: "Internal Server Error", | ||
}, | ||
}, | ||
{ | ||
status: 500, | ||
statusText: "Internal Server Error", | ||
} | ||
); | ||
} | ||
}; |
Oops, something went wrong.