generated from scaffold-eth/scaffold-eth-2
-
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
labintsev
committed
Dec 11, 2024
1 parent
cffba96
commit f83fbdb
Showing
6 changed files
with
67 additions
and
280 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,28 @@ | ||
import { Choice, Question } from "./definitions"; | ||
import { sql } from "@vercel/postgres"; | ||
|
||
export async function fetchQuestions() { | ||
try { | ||
// Artificially delay a response for demo purposes. | ||
// Don't do this in production :) | ||
|
||
// console.log('Fetching revenue data...'); | ||
// await new Promise((resolve) => setTimeout(resolve, 3000)); | ||
|
||
const questions = await sql<Question>`SELECT * FROM questions`; | ||
|
||
const choices = await sql<Choice>`SELECT * FROM choices`; | ||
|
||
// const q_rows = questions.rows; | ||
|
||
// todo join questions and choices | ||
|
||
console.log("Questions fetched ", questions); | ||
console.log("Choices fetched ", choices); | ||
|
||
return questions.rows; | ||
} catch (error) { | ||
console.error("Database Error:", error); | ||
throw new Error("Failed to fetch data."); | ||
} | ||
} |
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,9 @@ | ||
export type Question = { | ||
question: string; | ||
is_active: number; | ||
}; | ||
|
||
export type Choice = { | ||
question_id: string; | ||
text: string; | ||
}; |
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
Oops, something went wrong.