Skip to content

Commit 30ad10c

Browse files
Update example/with-typescript-nextjs to latest version of the drivers #64
1 parent 45426f0 commit 30ad10c

File tree

10 files changed

+355
-221
lines changed

10 files changed

+355
-221
lines changed

examples/with-plain-javascript.zip

2.22 MB
Binary file not shown.

examples/with-plain-javascript/app.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Using @sqlitecloud/drivers with plain Javascript
2+
// app.js - example of @sqlitecloud/drivers using Javascript in Node.js
33
//
44

55
var sqlitecloud = require('@sqlitecloud/drivers')
@@ -14,7 +14,7 @@ async function selectTracks() {
1414

1515
// run async query
1616
var tracks = await database.sql`USE DATABASE chinook.sqlite; SELECT * FROM tracks LIMIT 20;`
17-
console.log(`getTracks returned:`, tracks)
17+
console.log(`selectTracks returned:`, tracks)
1818

1919
// You can also use all the regular sqlite3 api with callbacks, see:
2020
// https://docs.sqlitecloud.io/docs/sdk/js/intro
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# connection string for chinook.db on sqlitecloud.io
2-
CHINOOK_URL="sqlitecloud://user:password@host.sqlite.cloud:8860/chinook.db"
2+
DATABASE_URL="sqlitecloud://user:password@host.sqlite.cloud:8860"

examples/with-typescript-nextjs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ First, run the development server:
66
npm run dev
77
```
88

9-
Open [http://localhost:3000/api/hello](http://localhost:3000) with your browser to see the result.
9+
Open [http://localhost:3000/api/hello](http://localhost:3000/api/hello) with your browser to see the result.
1010

1111
You can start editing the API route by modifying `app/api/hello/route.ts`. The page auto-updates as you edit the file.
1212

examples/with-typescript-nextjs/app/api/hello/route.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@
22
// GET /api/hello - example API route using sqlitecloud-js
33
//
44

5-
import { NextRequest, NextResponse } from "next/server";
6-
import { Database } from "sqlitecloud-js";
5+
import { NextRequest, NextResponse } from 'next/server'
6+
import { Database } from '@sqlitecloud/drivers'
77

88
// connection string is defined in .env file
9-
const CHINOOK_URL = process.env.CHINOOK_URL as string;
10-
console.assert(CHINOOK_URL, "Please configure a .env file with CHINOOK_URL pointing to the chinook database, see .env.example");
9+
const DATABASE_URL = process.env.DATABASE_URL as string
10+
console.assert(DATABASE_URL, 'Please configure a .env file with DATABASE_URL pointing to the chinook database, see .env.example')
1111

1212
// route for /api/hello
1313
export async function GET(request: NextRequest) {
1414
// connect to database using connection string provided in https://dashboard.sqlitecloud.io/
15-
const database = new Database(CHINOOK_URL);
15+
const database = new Database(DATABASE_URL)
1616

1717
// retrieve rows from chinook database using a plain SQL query
18-
const tracks = await database.sql`SELECT * FROM tracks LIMIT 20`;
18+
const tracks = await database.sql`USE DATABASE chinook.sqlite; SELECT * FROM tracks LIMIT 20;`
1919

2020
// return as json response
21-
return NextResponse.json<{data: any}>({ data: tracks });
21+
return NextResponse.json<{ data: any }>({ data: tracks })
2222
}

examples/with-typescript-nextjs/app/page.module.css

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,7 @@
178178
border-radius: 0;
179179
border: none;
180180
border-bottom: 1px solid rgba(var(--callout-border-rgb), 0.25);
181-
background: linear-gradient(
182-
to bottom,
183-
rgba(var(--background-start-rgb), 1),
184-
rgba(var(--callout-rgb), 0.5)
185-
);
181+
background: linear-gradient(to bottom, rgba(var(--background-start-rgb), 1), rgba(var(--callout-rgb), 0.5));
186182
background-clip: padding-box;
187183
backdrop-filter: blur(24px);
188184
}
@@ -193,11 +189,7 @@
193189
inset: auto 0 0;
194190
padding: 2rem;
195191
height: 200px;
196-
background: linear-gradient(
197-
to bottom,
198-
transparent 0%,
199-
rgb(var(--background-end-rgb)) 40%
200-
);
192+
background: linear-gradient(to bottom, transparent 0%, rgb(var(--background-end-rgb)) 40%);
201193
z-index: 1;
202194
}
203195
}

examples/with-typescript-nextjs/app/page.tsx

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -5,90 +5,7 @@ export default function Home() {
55
return (
66
<main className={styles.main}>
77
<div className={styles.description}>
8-
<p>
9-
Get started by editing&nbsp;
10-
<code className={styles.code}>app/page.tsx</code>
11-
</p>
12-
<div>
13-
<a
14-
href="https://vercel.com?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
15-
target="_blank"
16-
rel="noopener noreferrer"
17-
>
18-
By{' '}
19-
<Image
20-
src="/vercel.svg"
21-
alt="Vercel Logo"
22-
className={styles.vercelLogo}
23-
width={100}
24-
height={24}
25-
priority
26-
/>
27-
</a>
28-
</div>
29-
</div>
30-
31-
<div className={styles.center}>
32-
<Image
33-
className={styles.logo}
34-
src="/next.svg"
35-
alt="Next.js Logo"
36-
width={180}
37-
height={37}
38-
priority
39-
/>
40-
</div>
41-
42-
<div className={styles.grid}>
43-
<a
44-
href="https://nextjs.org/docs?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
45-
className={styles.card}
46-
target="_blank"
47-
rel="noopener noreferrer"
48-
>
49-
<h2>
50-
Docs <span>-&gt;</span>
51-
</h2>
52-
<p>Find in-depth information about Next.js features and API.</p>
53-
</a>
54-
55-
<a
56-
href="https://nextjs.org/learn?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
57-
className={styles.card}
58-
target="_blank"
59-
rel="noopener noreferrer"
60-
>
61-
<h2>
62-
Learn <span>-&gt;</span>
63-
</h2>
64-
<p>Learn about Next.js in an interactive course with&nbsp;quizzes!</p>
65-
</a>
66-
67-
<a
68-
href="https://vercel.com/templates?framework=next.js&utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
69-
className={styles.card}
70-
target="_blank"
71-
rel="noopener noreferrer"
72-
>
73-
<h2>
74-
Templates <span>-&gt;</span>
75-
</h2>
76-
<p>Explore starter templates for Next.js.</p>
77-
</a>
78-
79-
<a
80-
href="https://vercel.com/new?utm_source=create-next-app&utm_medium=appdir-template&utm_campaign=create-next-app"
81-
className={styles.card}
82-
target="_blank"
83-
rel="noopener noreferrer"
84-
>
85-
<h2>
86-
Deploy <span>-&gt;</span>
87-
</h2>
88-
<p>
89-
Instantly deploy your Next.js site to a shareable URL with Vercel.
90-
</p>
91-
</a>
8+
next.js json route: <a href="/api/hello">app/api/hello/</a>
929
</div>
9310
</main>
9411
)

0 commit comments

Comments
 (0)