Skip to content

Commit

Permalink
Merge pull request #2 from Mansive/db
Browse files Browse the repository at this point in the history
Connect to db
  • Loading branch information
Mansive authored Dec 22, 2023
2 parents a8e7bfb + 62b908f commit 6914197
Show file tree
Hide file tree
Showing 26 changed files with 350 additions and 14 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:

- name: Build
run: npx @cloudflare/next-on-pages@1
env:
XATA_API_KEY: ${{ secrets.XATA_API_KEY }}

- name: Publish to Cloudflare Pages
uses: cloudflare/pages-action@v1
Expand All @@ -49,7 +51,7 @@ jobs:
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
# Optional: Switch what branch you are publishing to.
# By default this will be the branch which triggered this workflow
branch: main
#branch: main
# Optional: Change the working directory
#workingDirectory: my-site
# Optional: Change the Wrangler version, allows you to point to a specific version or a tag such as `beta`
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts
.dev.vars
.env
.dev.vars
14 changes: 14 additions & 0 deletions .xata/migrations/.ledger
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
mig_clt8pr6ikbucdv445tkg_16264466
mig_clt8pvh51tlm97jou9tg_50da88fb
mig_clt8qep51tlm97joua5g_39219fe8
mig_clt8qg951tlm97joua7g_eb7523ab
mig_clt8qm151tlm97joua8g_a673c218
mig_clt8qneikbucdv445u9g_e3a10c45
mig_clt8qr9ufgk57snhcv90_e296b93f
mig_clt8r5951tlm97joua9g_9d118fb3
mig_clt8rb151tlm97jouaag_1632a9c3
mig_clt8u51ufgk57snhcva0_c24aa583
mig_clt8ul6ikbucdv445uag_dc5e54ff
mig_clt8up6ikbucdv445ubg_47dad0b9
mig_clt8ut951tlm97jouabg_d5ce08c4
mig_clt8v0mikbucdv445ucg_25569b27
11 changes: 11 additions & 0 deletions .xata/migrations/mig_clt8pr6ikbucdv445tkg_16264466.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"id": "mig_clt8pr6ikbucdv445tkg",
"checksum": "1:16264466529c465708d58829438f3ea695865e100ec7d4f1a20e4ee89e81f4bb",
"operations": [
{
"addTable": {
"table": "Books"
}
}
]
}
16 changes: 16 additions & 0 deletions .xata/migrations/mig_clt8pvh51tlm97jou9tg_50da88fb.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"id": "mig_clt8pvh51tlm97jou9tg",
"parentID": "mig_clt8pr6ikbucdv445tkg",
"checksum": "1:50da88fbc9a220e6ec2f5d16fd1ea79af9e9384b2c785b3ef5f0dc92d7fcac9b",
"operations": [
{
"addColumn": {
"column": {
"name": "title",
"type": "string"
},
"table": "Books"
}
}
]
}
12 changes: 12 additions & 0 deletions .xata/migrations/mig_clt8qep51tlm97joua5g_39219fe8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"id": "mig_clt8qep51tlm97joua5g",
"parentID": "mig_clt8pvh51tlm97jou9tg",
"checksum": "1:39219fe868101ac292a454d1c1713e8b8370a1b4822427ce40a5842d3fbc58d2",
"operations": [
{
"removeTable": {
"table": "Books"
}
}
]
}
12 changes: 12 additions & 0 deletions .xata/migrations/mig_clt8qg951tlm97joua7g_eb7523ab.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"id": "mig_clt8qg951tlm97joua7g",
"parentID": "mig_clt8qep51tlm97joua5g",
"checksum": "1:eb7523ab119c0b2a29ec8f874ccb31e1bd0574a46093cadf76c3ca00eceabe85",
"operations": [
{
"addTable": {
"table": "Books"
}
}
]
}
18 changes: 18 additions & 0 deletions .xata/migrations/mig_clt8qm151tlm97joua8g_a673c218.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"id": "mig_clt8qm151tlm97joua8g",
"parentID": "mig_clt8qg951tlm97joua7g",
"checksum": "1:a673c218ed69470cd5ae2d9d824433ad1ff1c0e4ba17f6dc4f78c85b303f2f9b",
"operations": [
{
"addColumn": {
"column": {
"name": "title",
"type": "string",
"notNull": true,
"defaultValue": "\"\""
},
"table": "Books"
}
}
]
}
13 changes: 13 additions & 0 deletions .xata/migrations/mig_clt8qneikbucdv445u9g_e3a10c45.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"id": "mig_clt8qneikbucdv445u9g",
"parentID": "mig_clt8qm151tlm97joua8g",
"checksum": "1:e3a10c455e3f8ea6a61a2b58a52101a8e2c6586a54b1510400c842ae3f5793e4",
"operations": [
{
"removeColumn": {
"column": "title",
"table": "Books"
}
}
]
}
18 changes: 18 additions & 0 deletions .xata/migrations/mig_clt8qr9ufgk57snhcv90_e296b93f.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"id": "mig_clt8qr9ufgk57snhcv90",
"parentID": "mig_clt8qneikbucdv445u9g",
"checksum": "1:e296b93f1c5d4f53bbf4e583cc22c443b20c6cd6703c37a35637f24c20f7edde",
"operations": [
{
"addColumn": {
"column": {
"name": "title",
"type": "string",
"notNull": true,
"defaultValue": ""
},
"table": "Books"
}
}
]
}
18 changes: 18 additions & 0 deletions .xata/migrations/mig_clt8r5951tlm97joua9g_9d118fb3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"id": "mig_clt8r5951tlm97joua9g",
"parentID": "mig_clt8qr9ufgk57snhcv90",
"checksum": "1:9d118fb3dfbf5fed2be74bb8c498303289476fab4c3cb64af21b9768dfd6f58f",
"operations": [
{
"addColumn": {
"column": {
"name": "true_title",
"type": "string",
"notNull": true,
"defaultValue": ""
},
"table": "Books"
}
}
]
}
18 changes: 18 additions & 0 deletions .xata/migrations/mig_clt8rb151tlm97jouaag_1632a9c3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"id": "mig_clt8rb151tlm97jouaag",
"parentID": "mig_clt8r5951tlm97joua9g",
"checksum": "1:1632a9c3a49f26b927bcb6d91a6862dfa6073f189ce63e8da230670adc2816da",
"operations": [
{
"addColumn": {
"column": {
"name": "extension",
"type": "string",
"notNull": true,
"defaultValue": ""
},
"table": "Books"
}
}
]
}
18 changes: 18 additions & 0 deletions .xata/migrations/mig_clt8u51ufgk57snhcva0_c24aa583.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"id": "mig_clt8u51ufgk57snhcva0",
"parentID": "mig_clt8rb151tlm97jouaag",
"checksum": "1:c24aa583a4b4d4cdff434f8eb70c5b59c3e5af80496ea80bc399362c0ff67db3",
"operations": [
{
"addColumn": {
"column": {
"name": "size",
"type": "int",
"notNull": true,
"defaultValue": "0"
},
"table": "Books"
}
}
]
}
16 changes: 16 additions & 0 deletions .xata/migrations/mig_clt8ul6ikbucdv445uag_dc5e54ff.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"id": "mig_clt8ul6ikbucdv445uag",
"parentID": "mig_clt8u51ufgk57snhcva0",
"checksum": "1:dc5e54ff5462e0144d3633914899f97b0ce8d2c37ea83541bcea7123ab91635b",
"operations": [
{
"addColumn": {
"column": {
"name": "sources",
"type": "multiple"
},
"table": "Books"
}
}
]
}
13 changes: 13 additions & 0 deletions .xata/migrations/mig_clt8up6ikbucdv445ubg_47dad0b9.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"id": "mig_clt8up6ikbucdv445ubg",
"parentID": "mig_clt8ul6ikbucdv445uag",
"checksum": "1:47dad0b9d387315cddc4f9a1b25dddb53f93ed48790efd2e186803c72ac7dcc8",
"operations": [
{
"removeColumn": {
"column": "sources",
"table": "Books"
}
}
]
}
16 changes: 16 additions & 0 deletions .xata/migrations/mig_clt8ut951tlm97jouabg_d5ce08c4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"id": "mig_clt8ut951tlm97jouabg",
"parentID": "mig_clt8up6ikbucdv445ubg",
"checksum": "1:d5ce08c408263f80863055712da3e1bf066731e115fba5e10f2e40ee7d41007e",
"operations": [
{
"addColumn": {
"column": {
"name": "sources",
"type": "multiple"
},
"table": "Books"
}
}
]
}
16 changes: 16 additions & 0 deletions .xata/migrations/mig_clt8v0mikbucdv445ucg_25569b27.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"id": "mig_clt8v0mikbucdv445ucg",
"parentID": "mig_clt8ut951tlm97jouabg",
"checksum": "1:25569b27226827636af25095c26d23e44d59e489c57aba56575b975a0a0ce596",
"operations": [
{
"addColumn": {
"column": {
"name": "md5",
"type": "string"
},
"table": "Books"
}
}
]
}
1 change: 1 addition & 0 deletions .xata/version/compatibility.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"@xata.io/cli":{"latest":"0.15.3","compatibility":[{"range":">=0.0.0"}]},"@xata.io/client":{"latest":"0.28.2","compatibility":[{"range":">=0.0.0"}]}}
6 changes: 6 additions & 0 deletions .xatarc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"databaseURL": "https://lolibrary-92ghbn.us-east-1.xata.sh/db/lolibrary",
"codegen": {
"output": "src/lib/xata.ts"
}
}
10 changes: 9 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@react-three/drei": "^9.90.0",
"@react-three/fiber": "^8.15.12",
"@types/three": "^0.159.0",
"@xata.io/client": "^0.28.2",
"framer-motion": "^10.16.14",
"next": "14.0.3",
"react": "^18",
Expand Down
25 changes: 25 additions & 0 deletions src/app/api/search/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { getXataClient } from "@/lib/xata";
import { NextRequest, NextResponse } from "next/server";

export const runtime = "edge";

const xata = getXataClient();

export async function GET(request: NextRequest) {
const searchParams: string = decodeURIComponent(
request.nextUrl.searchParams.toString()
);
if (searchParams.length > 128) {
return NextResponse.json(
{ message: "Search entry is too long" },
{ status: 403 }
);
}

const results = await xata.db.Books.search(searchParams, {
target: ["title"],
fuzziness: 0,
});

return NextResponse.json(results);
}
23 changes: 14 additions & 9 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import SearchBar from "@/components/SearchBar";
import SearchResultList from "@/components/SearchResultList";
import Spinner from "@/components/Spinner";

import { Book, BOOKS } from "@/data/book-data";
import { Book } from "@/data/book-data";

import styles from "./page.module.css";

Expand All @@ -22,13 +22,18 @@ export default function Home() {

setStatus("loading");

setTimeout(() => {
const nextSearchResults = BOOKS.filter(({ title }) =>
title.includes(searchTerm)
);
setSearchResults(nextSearchResults);
setStatus("success");
}, 1500);
try {
const response = await fetch("/api/search?query=" + searchTerm);
if (!response.ok) {
throw new Error();
}
const data = await response.json();
setSearchResults(data["records"]);
data["records"].length == 0 ? setStatus("idle") : setStatus("success");
} catch (error) {
setStatus("idle");
//setStatus("error");
}
};

return (
Expand All @@ -46,7 +51,7 @@ export default function Home() {
onChange={(event: React.ChangeEvent<HTMLInputElement>) => {
setSearchTerm(event.target.value);
}}
maxLength={64}
maxLength={128}
/>
</form>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type CardInterface = {
id: string;
title: string;
sources: string[];
size: number;
size: string;
extension: string;
};

Expand Down
Loading

0 comments on commit 6914197

Please sign in to comment.