-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
drizzle, d1, OAuthを動作させるために簡易的なアプリケーションを作成
- Loading branch information
Showing
25 changed files
with
499 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
AUTH_SECRET = "" | ||
GOOGLE_CALLBACK_BASE_URL = "http://localhost:5173" | ||
GOOGLE_CLIENT_ID = "" | ||
GOOGLE_CLIENT_SECRET = "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,6 @@ node_modules | |
/.cache | ||
/build | ||
.env | ||
.dev.vars | ||
|
||
.wrangler | ||
.dev.vars |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
DROP TABLE IF EXISTS posts; | ||
DROP TABLE IF EXISTS users; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { drizzle } from "drizzle-orm/d1"; | ||
|
||
export const getDBClient = (d1: D1Database) => { | ||
const db = drizzle(d1, { logger: import.meta.env.DEV }); | ||
return db; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
CREATE TABLE `posts` ( | ||
`id` integer PRIMARY KEY NOT NULL, | ||
`body` text, | ||
`user_id` integer, | ||
`created_at` text DEFAULT (current_timestamp) NOT NULL, | ||
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE `users` ( | ||
`id` integer PRIMARY KEY NOT NULL, | ||
`provider` text NOT NULL, | ||
`provider_id` text NOT NULL, | ||
`name` text NOT NULL, | ||
`icon` text, | ||
`created_at` text DEFAULT (current_timestamp) NOT NULL | ||
); | ||
--> statement-breakpoint | ||
CREATE UNIQUE INDEX `users_provider_id_unique` ON `users` (`provider_id`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
{ | ||
"version": "6", | ||
"dialect": "sqlite", | ||
"id": "a0c45071-1d9d-4fff-b96d-52932ed1a195", | ||
"prevId": "00000000-0000-0000-0000-000000000000", | ||
"tables": { | ||
"posts": { | ||
"name": "posts", | ||
"columns": { | ||
"id": { | ||
"name": "id", | ||
"type": "integer", | ||
"primaryKey": true, | ||
"notNull": true, | ||
"autoincrement": false | ||
}, | ||
"body": { | ||
"name": "body", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
}, | ||
"user_id": { | ||
"name": "user_id", | ||
"type": "integer", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
}, | ||
"created_at": { | ||
"name": "created_at", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false, | ||
"default": "(current_timestamp)" | ||
} | ||
}, | ||
"indexes": {}, | ||
"foreignKeys": { | ||
"posts_user_id_users_id_fk": { | ||
"name": "posts_user_id_users_id_fk", | ||
"tableFrom": "posts", | ||
"tableTo": "users", | ||
"columnsFrom": [ | ||
"user_id" | ||
], | ||
"columnsTo": [ | ||
"id" | ||
], | ||
"onDelete": "no action", | ||
"onUpdate": "no action" | ||
} | ||
}, | ||
"compositePrimaryKeys": {}, | ||
"uniqueConstraints": {} | ||
}, | ||
"users": { | ||
"name": "users", | ||
"columns": { | ||
"id": { | ||
"name": "id", | ||
"type": "integer", | ||
"primaryKey": true, | ||
"notNull": true, | ||
"autoincrement": false | ||
}, | ||
"provider": { | ||
"name": "provider", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false | ||
}, | ||
"provider_id": { | ||
"name": "provider_id", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false | ||
}, | ||
"name": { | ||
"name": "name", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false | ||
}, | ||
"icon": { | ||
"name": "icon", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": false, | ||
"autoincrement": false | ||
}, | ||
"created_at": { | ||
"name": "created_at", | ||
"type": "text", | ||
"primaryKey": false, | ||
"notNull": true, | ||
"autoincrement": false, | ||
"default": "(current_timestamp)" | ||
} | ||
}, | ||
"indexes": { | ||
"users_provider_id_unique": { | ||
"name": "users_provider_id_unique", | ||
"columns": [ | ||
"provider_id" | ||
], | ||
"isUnique": true | ||
} | ||
}, | ||
"foreignKeys": {}, | ||
"compositePrimaryKeys": {}, | ||
"uniqueConstraints": {} | ||
} | ||
}, | ||
"enums": {}, | ||
"_meta": { | ||
"schemas": {}, | ||
"tables": {}, | ||
"columns": {} | ||
}, | ||
"internal": { | ||
"indexes": {} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { sql } from "drizzle-orm"; | ||
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core"; | ||
|
||
export const users = sqliteTable("users", { | ||
id: integer("id").primaryKey(), | ||
provider: text("provider").notNull(), | ||
providerId: text("provider_id").notNull().unique(), | ||
name: text("name").notNull(), | ||
icon: text("icon"), | ||
createdAt: text("created_at") | ||
.notNull() | ||
.default(sql`(current_timestamp)`), | ||
}); | ||
|
||
export const posts = sqliteTable("posts", { | ||
id: integer("id").primaryKey(), | ||
body: text("body"), | ||
userId: integer("user_id").references(() => users.id), | ||
createdAt: text("created_at") | ||
.notNull() | ||
.default(sql`(current_timestamp)`), | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.