-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.jsx
More file actions
48 lines (39 loc) · 932 Bytes
/
App.jsx
File metadata and controls
48 lines (39 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { useEffect, useState } from "react";
import { Database } from "@sqlitecloud/drivers";
let db = null
function getDatabase() {
if (!db || !db.isConnected()) {
db = new Database(import.meta.env.VITE_DATABASE_URL);
}
return db;
}
function App() {
const [data, setData] = useState([]);
const getAlbums = async () => {
const result = await getDatabase().sql(`
USE DATABASE chinook.sqlite;
SELECT albums.AlbumId as id, albums.Title as title, artists.name as artist
FROM albums
INNER JOIN artists
WHERE artists.ArtistId = albums.ArtistId
LIMIT 20;
`);
setData(result);
};
useEffect(() => {
getAlbums();
}, []);
return (
<div>
<h1>Albums</h1>
<ul>
{data.map((album) => (
<li key={album.id}>
{album.title} by {album.artist}
</li>
))}
</ul>
</div>
);
}
export default App;