Skip to content

Commit

Permalink
Establish db connection and basic search
Browse files Browse the repository at this point in the history
  • Loading branch information
Mansive committed Dec 20, 2023
1 parent 0ee9d83 commit b088846
Show file tree
Hide file tree
Showing 22 changed files with 321 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts


.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
19 changes: 19 additions & 0 deletions src/app/api/search/route.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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()
);

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

return NextResponse.json({ results });
}
52 changes: 52 additions & 0 deletions src/lib/xata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Generated by Xata Codegen 0.28.2. Please do not edit.
import { buildClient } from "@xata.io/client";
import type {
BaseClientOptions,
SchemaInference,
XataRecord,
} from "@xata.io/client";

const tables = [
{
name: "Books",
columns: [
{ name: "title", type: "string", notNull: true, defaultValue: "" },
{ name: "true_title", type: "string", notNull: true, defaultValue: "" },
{ name: "extension", type: "string", notNull: true, defaultValue: "" },
{ name: "size", type: "int", notNull: true, defaultValue: "0" },
{ name: "sources", type: "multiple" },
{ name: "md5", type: "string" },
],
},
] as const;

export type SchemaTables = typeof tables;
export type InferredTypes = SchemaInference<SchemaTables>;

export type Books = InferredTypes["Books"];
export type BooksRecord = Books & XataRecord;

export type DatabaseSchema = {
Books: BooksRecord;
};

const DatabaseClient = buildClient();

const defaultOptions = {
databaseURL: "https://lolibrary-92ghbn.us-east-1.xata.sh/db/lolibrary",
};

export class XataClient extends DatabaseClient<DatabaseSchema> {
constructor(options?: BaseClientOptions) {
super({ ...defaultOptions, ...options }, tables);
}
}

let instance: XataClient | undefined = undefined;

export const getXataClient = () => {
if (instance) return instance;

instance = new XataClient();
return instance;
};

0 comments on commit b088846

Please sign in to comment.