Files
9870faf789 Fix export function name on docs/routing/layouts-and-templates (#65240)
### 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]>
2024-05-01 11:20:45 -07:00

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,
}}
/>
));
}