mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
### What? Fix export function name on docs/routing/layouts-and-templates ### Why? The way it is, it will return an error to the user following the tutorial: `Unsupported Server Component type: undefined / next js 13` ### How? - Change `Links()` function export to `NavLinks()` --------- Co-authored-by: JJ Kasper <[email protected]>
36 lines
917 B
TypeScript
36 lines
917 B
TypeScript
import { type TodoItem, Todo } from "./todo";
|
|
|
|
import { db } from "@/lib/turso";
|
|
|
|
// The code below can be removed in production apps
|
|
// Useful for getting started locally with SQLite
|
|
async function findOrCreateTodosTable() {
|
|
const result = await db.execute(
|
|
"SELECT name FROM sqlite_master WHERE type='table' AND name='todos'",
|
|
);
|
|
|
|
if (!result || result?.rows?.length === 0) {
|
|
await db.execute(
|
|
"CREATE TABLE todos(id INTEGER PRIMARY KEY AUTOINCREMENT, description TEXT NOT NULL)",
|
|
);
|
|
}
|
|
}
|
|
|
|
export async function TodoList() {
|
|
await findOrCreateTodosTable();
|
|
const result = await db.execute("SELECT * FROM todos");
|
|
const rows = result.rows as unknown as TodoItem[];
|
|
|
|
if (!result || result?.rows?.length === 0) return null;
|
|
|
|
return rows.map((row, index) => (
|
|
<Todo
|
|
key={index}
|
|
item={{
|
|
id: row.id,
|
|
description: row.description,
|
|
}}
|
|
/>
|
|
));
|
|
}
|