From 277914ca2ee8653ca36efba6930ed1af577e95bf Mon Sep 17 00:00:00 2001 From: Andrew Galvan Date: Sun, 15 Oct 2023 23:34:16 -0700 Subject: [PATCH 1/7] copy files --- drizzle-orm/.eslintrc.js | 4 ++++ drizzle-orm/.gitignore | 6 ++++++ drizzle-orm/app/root.tsx | 32 ++++++++++++++++++++++++++++++ drizzle-orm/app/routes/_index.tsx | 7 +++++++ drizzle-orm/package.json | 29 +++++++++++++++++++++++++++ drizzle-orm/public/favicon.ico | Bin 0 -> 16958 bytes drizzle-orm/remix.config.js | 11 ++++++++++ drizzle-orm/remix.env.d.ts | 2 ++ drizzle-orm/sandbox.config.json | 7 +++++++ drizzle-orm/tsconfig.json | 22 ++++++++++++++++++++ 10 files changed, 120 insertions(+) create mode 100644 drizzle-orm/.eslintrc.js create mode 100644 drizzle-orm/.gitignore create mode 100644 drizzle-orm/app/root.tsx create mode 100644 drizzle-orm/app/routes/_index.tsx create mode 100644 drizzle-orm/package.json create mode 100644 drizzle-orm/public/favicon.ico create mode 100644 drizzle-orm/remix.config.js create mode 100644 drizzle-orm/remix.env.d.ts create mode 100644 drizzle-orm/sandbox.config.json create mode 100644 drizzle-orm/tsconfig.json diff --git a/drizzle-orm/.eslintrc.js b/drizzle-orm/.eslintrc.js new file mode 100644 index 00000000..2061cd22 --- /dev/null +++ b/drizzle-orm/.eslintrc.js @@ -0,0 +1,4 @@ +/** @type {import('eslint').Linter.Config} */ +module.exports = { + extends: ["@remix-run/eslint-config", "@remix-run/eslint-config/node"], +}; diff --git a/drizzle-orm/.gitignore b/drizzle-orm/.gitignore new file mode 100644 index 00000000..3f7bf98d --- /dev/null +++ b/drizzle-orm/.gitignore @@ -0,0 +1,6 @@ +node_modules + +/.cache +/build +/public/build +.env diff --git a/drizzle-orm/app/root.tsx b/drizzle-orm/app/root.tsx new file mode 100644 index 00000000..927a0f74 --- /dev/null +++ b/drizzle-orm/app/root.tsx @@ -0,0 +1,32 @@ +import type { MetaFunction } from "@remix-run/node"; +import { + Links, + LiveReload, + Meta, + Outlet, + Scripts, + ScrollRestoration, +} from "@remix-run/react"; + +export const meta: MetaFunction = () => ({ + charset: "utf-8", + title: "New Remix App", + viewport: "width=device-width,initial-scale=1", +}); + +export default function App() { + return ( + + + + + + + + + + + + + ); +} diff --git a/drizzle-orm/app/routes/_index.tsx b/drizzle-orm/app/routes/_index.tsx new file mode 100644 index 00000000..58245323 --- /dev/null +++ b/drizzle-orm/app/routes/_index.tsx @@ -0,0 +1,7 @@ +export default function Index() { + return ( +
+

Welcome to Remix

+
+ ); +} diff --git a/drizzle-orm/package.json b/drizzle-orm/package.json new file mode 100644 index 00000000..a437590d --- /dev/null +++ b/drizzle-orm/package.json @@ -0,0 +1,29 @@ +{ + "private": true, + "sideEffects": false, + "scripts": { + "build": "remix build", + "dev": "remix dev", + "start": "remix-serve build", + "typecheck": "tsc" + }, + "dependencies": { + "@remix-run/node": "^1.19.3", + "@remix-run/react": "^1.19.3", + "@remix-run/serve": "^1.19.3", + "isbot": "^3.6.5", + "react": "^18.2.0", + "react-dom": "^18.2.0" + }, + "devDependencies": { + "@remix-run/dev": "^1.19.3", + "@remix-run/eslint-config": "^1.19.3", + "@types/react": "^18.0.25", + "@types/react-dom": "^18.0.8", + "eslint": "^8.27.0", + "typescript": "^4.8.4" + }, + "engines": { + "node": ">=14.0.0" + } +} diff --git a/drizzle-orm/public/favicon.ico b/drizzle-orm/public/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..8830cf6821b354114848e6354889b8ecf6d2bc61 GIT binary patch literal 16958 zcmeI3+jCXb9mnJN2h^uNlXH@jlam{_a8F3W{T}Wih>9YJpaf7TUbu)A5fv|h7OMfR zR;q$lr&D!wv|c)`wcw1?>4QT1(&|jdsrI2h`Rn)dTW5t$8pz=s3_5L?#oBxAowe8R z_WfPfN?F+@`q$D@rvC?(W!uWieppskmQ~YG*>*L?{img@tWpnYXZslxeh#TSUS3{q z1Ju6JcfQSbQuORq69@YK(X-3c9vC2c2a2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Wt@NEd<$~n>RQL{ z+o;->n)+~0tt(u|o_9h!T`%M8%)w2awpV9b*xz9Pl-daUJm3y-HT%xg`^mFd6LBeL z!0~s;zEr)Bn9x)I(wx`;JVwvRcc^io2XX(Nn3vr3dgbrr@YJ?K3w18P*52^ieBCQP z=Up1V$N2~5ppJHRTeY8QfM(7Yv&RG7oWJAyv?c3g(29)P)u;_o&w|&)HGDIinXT~p z3;S|e$=&Tek9Wn!`cdY+d-w@o`37}x{(hl>ykB|%9yB$CGdIcl7Z?d&lJ%}QHck77 zJPR%C+s2w1_Dl_pxu6$Zi!`HmoD-%7OD@7%lKLL^Ixd9VlRSW*o&$^iQ2z+}hTgH) z#91TO#+jH<`w4L}XWOt(`gqM*uTUcky`O(mEyU|4dJoy6*UZJ7%*}ajuos%~>&P2j zk23f5<@GeV?(?`l=ih+D8t`d72xrUjv0wsg;%s1@*2p?TQ;n2$pV7h?_T%sL>iL@w zZ{lmc<|B7!e&o!zs6RW+u8+aDyUdG>ZS(v&rT$QVymB7sEC@VsK1dg^3F@K90-wYB zX!we79qx`(6LA>F$~{{xE8-3Wzyfe`+Lsce(?uj{k@lb97YTJt#>l*Z&LyKX@zjmu?UJC9w~;|NsB{%7G}y*uNDBxirfC EKbET!0{{R3 literal 0 HcmV?d00001 diff --git a/drizzle-orm/remix.config.js b/drizzle-orm/remix.config.js new file mode 100644 index 00000000..ca00ba94 --- /dev/null +++ b/drizzle-orm/remix.config.js @@ -0,0 +1,11 @@ +/** @type {import('@remix-run/dev').AppConfig} */ +module.exports = { + future: { + v2_routeConvention: true, + }, + ignoredRouteFiles: ["**/.*"], + // appDirectory: "app", + // assetsBuildDirectory: "public/build", + // publicPath: "/build/", + // serverBuildPath: "build/index.js", +}; diff --git a/drizzle-orm/remix.env.d.ts b/drizzle-orm/remix.env.d.ts new file mode 100644 index 00000000..dcf8c45e --- /dev/null +++ b/drizzle-orm/remix.env.d.ts @@ -0,0 +1,2 @@ +/// +/// diff --git a/drizzle-orm/sandbox.config.json b/drizzle-orm/sandbox.config.json new file mode 100644 index 00000000..f92e0250 --- /dev/null +++ b/drizzle-orm/sandbox.config.json @@ -0,0 +1,7 @@ +{ + "hardReloadOnChange": true, + "template": "remix", + "container": { + "port": 3000 + } +} diff --git a/drizzle-orm/tsconfig.json b/drizzle-orm/tsconfig.json new file mode 100644 index 00000000..20f8a386 --- /dev/null +++ b/drizzle-orm/tsconfig.json @@ -0,0 +1,22 @@ +{ + "include": ["remix.env.d.ts", "**/*.ts", "**/*.tsx"], + "compilerOptions": { + "lib": ["DOM", "DOM.Iterable", "ES2019"], + "isolatedModules": true, + "esModuleInterop": true, + "jsx": "react-jsx", + "moduleResolution": "node", + "resolveJsonModule": true, + "target": "ES2019", + "strict": true, + "allowJs": true, + "forceConsistentCasingInFileNames": true, + "baseUrl": ".", + "paths": { + "~/*": ["./app/*"] + }, + + // Remix takes care of building everything in `remix build`. + "noEmit": true + } +} From 2f6cdb7faeabc743fcfc63ad5f6e4db9ca08e120 Mon Sep 17 00:00:00 2001 From: Andrew Galvan Date: Sun, 15 Oct 2023 23:34:28 -0700 Subject: [PATCH 2/7] simple readme --- drizzle-orm/README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 drizzle-orm/README.md diff --git a/drizzle-orm/README.md b/drizzle-orm/README.md new file mode 100644 index 00000000..ff1a2a08 --- /dev/null +++ b/drizzle-orm/README.md @@ -0,0 +1,21 @@ +# Drizzle ORM Example + +In this example we will setup Drizzle ORM with Remix. + +## Preview + +Open this example on [CodeSandbox](https://codesandbox.com): + +[![Open in CodeSandbox](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/github/remix-run/examples/tree/main/drizzle-orm) + +## Example + +Relevant files: + +- [drizzle](./drizzle) migrations and drizzle-related meta information +- [app/schema.ts] table schemas and data models +- [app/db.server.ts] setup database client + +## Related Links + +[Drizzle ORM](https://orm.drizzle.team) From d38d1e45b9d818031ae0faec565f6da5046bbc0b Mon Sep 17 00:00:00 2001 From: Andrew Galvan Date: Mon, 16 Oct 2023 00:39:07 -0700 Subject: [PATCH 3/7] drizzle example --- drizzle-orm/.gitignore | 1 + drizzle-orm/README.md | 4 +- drizzle-orm/app/db.server.ts | 10 ++++ drizzle-orm/app/routes/_index.tsx | 51 +++++++++++++++++++++ drizzle-orm/app/schema.ts | 7 +++ drizzle-orm/drizzle.config.ts | 6 +++ drizzle-orm/drizzle/0000_mute_groot.sql | 4 ++ drizzle-orm/drizzle/meta/0000_snapshot.json | 38 +++++++++++++++ drizzle-orm/drizzle/meta/_journal.json | 13 ++++++ drizzle-orm/package.json | 5 ++ 10 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 drizzle-orm/app/db.server.ts create mode 100644 drizzle-orm/app/schema.ts create mode 100644 drizzle-orm/drizzle.config.ts create mode 100644 drizzle-orm/drizzle/0000_mute_groot.sql create mode 100644 drizzle-orm/drizzle/meta/0000_snapshot.json create mode 100644 drizzle-orm/drizzle/meta/_journal.json diff --git a/drizzle-orm/.gitignore b/drizzle-orm/.gitignore index 3f7bf98d..c7fb563d 100644 --- a/drizzle-orm/.gitignore +++ b/drizzle-orm/.gitignore @@ -4,3 +4,4 @@ node_modules /build /public/build .env +*.db diff --git a/drizzle-orm/README.md b/drizzle-orm/README.md index ff1a2a08..4a9e8d04 100644 --- a/drizzle-orm/README.md +++ b/drizzle-orm/README.md @@ -13,8 +13,8 @@ Open this example on [CodeSandbox](https://codesandbox.com): Relevant files: - [drizzle](./drizzle) migrations and drizzle-related meta information -- [app/schema.ts] table schemas and data models -- [app/db.server.ts] setup database client +- [app/db/db.server.ts] setup database client +- [package.json] add `db:*` scripts and drizzle dependencies ## Related Links diff --git a/drizzle-orm/app/db.server.ts b/drizzle-orm/app/db.server.ts new file mode 100644 index 00000000..c97f68ce --- /dev/null +++ b/drizzle-orm/app/db.server.ts @@ -0,0 +1,10 @@ +import Database from "better-sqlite3"; +import { drizzle } from "drizzle-orm/better-sqlite3"; +import { migrate } from "drizzle-orm/better-sqlite3/migrator"; +import * as schema from "./schema"; + +const sqlite = new Database("sqlite.db"); + +export const db = drizzle(sqlite, { schema }); + +migrate(db, { migrationsFolder: "drizzle" }); diff --git a/drizzle-orm/app/routes/_index.tsx b/drizzle-orm/app/routes/_index.tsx index 58245323..1152f7e8 100644 --- a/drizzle-orm/app/routes/_index.tsx +++ b/drizzle-orm/app/routes/_index.tsx @@ -1,7 +1,58 @@ +import { type ActionArgs } from "@remix-run/node"; +import { Form, useLoaderData } from "@remix-run/react"; +import { sql } from "drizzle-orm"; +import { db } from "~/db.server"; +import { example } from "~/schema"; + +export async function action({ request }: ActionArgs) { + let formData = await request.formData(); + let intent = formData.get("intent"); + + if (intent === "update") { + await db.insert(example).values({}); + return new Response(null, { status: 201 }); + } + + if (intent == "reset") { + await db.delete(example); + return new Response(null, { status: 204 }); + } + + return new Response(null, { status: 400 }); +} + +export function loader() { + let result = db + .select({ + count: sql`COUNT(*)`, + lastUpdated: sql`MAX(created_at)`, + }) + .from(example) + .get(); + + return { + count: result?.count ?? 0, + lastUpdated: result?.lastUpdated ?? "never", + }; +} + export default function Index() { + const { count, lastUpdated } = useLoaderData(); return (

Welcome to Remix

+

+ Count: {count}
+ Last updated: {lastUpdated} +

+
+ + +
); } diff --git a/drizzle-orm/app/schema.ts b/drizzle-orm/app/schema.ts new file mode 100644 index 00000000..98495e3a --- /dev/null +++ b/drizzle-orm/app/schema.ts @@ -0,0 +1,7 @@ +import { sql } from 'drizzle-orm' +import { sqliteTable, integer, text } from "drizzle-orm/sqlite-core"; + +export const example = sqliteTable('example', { + id: integer('id').primaryKey(), + createdAt: text('created_at').default(sql`CURRENT_TIMESTAMP`), +}) diff --git a/drizzle-orm/drizzle.config.ts b/drizzle-orm/drizzle.config.ts new file mode 100644 index 00000000..3ea082b0 --- /dev/null +++ b/drizzle-orm/drizzle.config.ts @@ -0,0 +1,6 @@ +import type { Config } from "drizzle-kit"; + +export default { + schema: "./app/schema.ts", + out: "./drizzle", +} satisfies Config; diff --git a/drizzle-orm/drizzle/0000_mute_groot.sql b/drizzle-orm/drizzle/0000_mute_groot.sql new file mode 100644 index 00000000..691bc165 --- /dev/null +++ b/drizzle-orm/drizzle/0000_mute_groot.sql @@ -0,0 +1,4 @@ +CREATE TABLE `example` ( + `id` integer PRIMARY KEY NOT NULL, + `created_at` text DEFAULT CURRENT_TIMESTAMP +); diff --git a/drizzle-orm/drizzle/meta/0000_snapshot.json b/drizzle-orm/drizzle/meta/0000_snapshot.json new file mode 100644 index 00000000..5fc7695f --- /dev/null +++ b/drizzle-orm/drizzle/meta/0000_snapshot.json @@ -0,0 +1,38 @@ +{ + "version": "5", + "dialect": "sqlite", + "id": "0be79972-b6bf-4225-88d7-95a723174903", + "prevId": "00000000-0000-0000-0000-000000000000", + "tables": { + "example": { + "name": "example", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + } + }, + "enums": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + } +} \ No newline at end of file diff --git a/drizzle-orm/drizzle/meta/_journal.json b/drizzle-orm/drizzle/meta/_journal.json new file mode 100644 index 00000000..4745c3ec --- /dev/null +++ b/drizzle-orm/drizzle/meta/_journal.json @@ -0,0 +1,13 @@ +{ + "version": "5", + "dialect": "sqlite", + "entries": [ + { + "idx": 0, + "version": "5", + "when": 1697441145549, + "tag": "0000_mute_groot", + "breakpoints": true + } + ] +} \ No newline at end of file diff --git a/drizzle-orm/package.json b/drizzle-orm/package.json index a437590d..7e9db94c 100644 --- a/drizzle-orm/package.json +++ b/drizzle-orm/package.json @@ -4,6 +4,7 @@ "scripts": { "build": "remix build", "dev": "remix dev", + "generate": "drizzle-kit generate:sqlite", "start": "remix-serve build", "typecheck": "tsc" }, @@ -11,6 +12,8 @@ "@remix-run/node": "^1.19.3", "@remix-run/react": "^1.19.3", "@remix-run/serve": "^1.19.3", + "better-sqlite3": "^9.0.0", + "drizzle-orm": "^0.28.6", "isbot": "^3.6.5", "react": "^18.2.0", "react-dom": "^18.2.0" @@ -18,8 +21,10 @@ "devDependencies": { "@remix-run/dev": "^1.19.3", "@remix-run/eslint-config": "^1.19.3", + "@types/better-sqlite3": "^7.6.5", "@types/react": "^18.0.25", "@types/react-dom": "^18.0.8", + "drizzle-kit": "^0.19.13", "eslint": "^8.27.0", "typescript": "^4.8.4" }, From 7d957ea019e839290e8539ffe26d3f5e0b0b1184 Mon Sep 17 00:00:00 2001 From: Andrew Galvan Date: Mon, 16 Oct 2023 00:59:10 -0700 Subject: [PATCH 4/7] use const --- drizzle-orm/app/routes/_index.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drizzle-orm/app/routes/_index.tsx b/drizzle-orm/app/routes/_index.tsx index 1152f7e8..c014cbdc 100644 --- a/drizzle-orm/app/routes/_index.tsx +++ b/drizzle-orm/app/routes/_index.tsx @@ -5,8 +5,8 @@ import { db } from "~/db.server"; import { example } from "~/schema"; export async function action({ request }: ActionArgs) { - let formData = await request.formData(); - let intent = formData.get("intent"); + const formData = await request.formData(); + const intent = formData.get("intent"); if (intent === "update") { await db.insert(example).values({}); @@ -22,7 +22,7 @@ export async function action({ request }: ActionArgs) { } export function loader() { - let result = db + const result = db .select({ count: sql`COUNT(*)`, lastUpdated: sql`MAX(created_at)`, From 4c58cfd8c608fdef7e6da059388f5c6f3be1b60b Mon Sep 17 00:00:00 2001 From: Andrew Galvan Date: Mon, 16 Oct 2023 01:01:50 -0700 Subject: [PATCH 5/7] update readme --- drizzle-orm/README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drizzle-orm/README.md b/drizzle-orm/README.md index 4a9e8d04..583c14ec 100644 --- a/drizzle-orm/README.md +++ b/drizzle-orm/README.md @@ -13,8 +13,9 @@ Open this example on [CodeSandbox](https://codesandbox.com): Relevant files: - [drizzle](./drizzle) migrations and drizzle-related meta information -- [app/db/db.server.ts] setup database client -- [package.json] add `db:*` scripts and drizzle dependencies +- [app/db.server.ts] setup database client +- [app/schema.ts] define database schema +- [package.json] add `generate` script and drizzle dependencies ## Related Links From dc362da48683bbdbffecc1017edc9ac111a205a5 Mon Sep 17 00:00:00 2001 From: Andrew Galvan Date: Mon, 16 Oct 2023 01:36:36 -0700 Subject: [PATCH 6/7] update example --- drizzle-orm/app/routes/_index.tsx | 37 +++++++++++++++++-------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/drizzle-orm/app/routes/_index.tsx b/drizzle-orm/app/routes/_index.tsx index c014cbdc..5c78a49e 100644 --- a/drizzle-orm/app/routes/_index.tsx +++ b/drizzle-orm/app/routes/_index.tsx @@ -8,7 +8,7 @@ export async function action({ request }: ActionArgs) { const formData = await request.formData(); const intent = formData.get("intent"); - if (intent === "update") { + if (intent === "add") { await db.insert(example).values({}); return new Response(null, { status: 201 }); } @@ -21,38 +21,41 @@ export async function action({ request }: ActionArgs) { return new Response(null, { status: 400 }); } -export function loader() { - const result = db - .select({ - count: sql`COUNT(*)`, - lastUpdated: sql`MAX(created_at)`, - }) +export async function loader() { + const rowsQuery = db.select().from(example); + + const lastUpdatedQuery = db + .select({ updated: sql`MAX(created_at)` }) .from(example) - .get(); + .execute() + .then((rows) => rows[0].updated); return { - count: result?.count ?? 0, - lastUpdated: result?.lastUpdated ?? "never", + rows: await rowsQuery, + lastUpdated: await lastUpdatedQuery, }; } export default function Index() { - const { count, lastUpdated } = useLoaderData(); + const { rows, lastUpdated } = useLoaderData(); + return (

Welcome to Remix

-

- Count: {count}
- Last updated: {lastUpdated} -

+

Last Updated: {lastUpdated ?? "--"}

-
+
    + {rows.map((row) => ( +
  • {row.id}
  • + ))} +
); } From 5212f8111aa1b24eb5e0da386f3f26fe7bdae3eb Mon Sep 17 00:00:00 2001 From: Andrew Galvan Date: Mon, 16 Oct 2023 07:25:56 -0700 Subject: [PATCH 7/7] alt query syntax --- drizzle-orm/app/routes/_index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drizzle-orm/app/routes/_index.tsx b/drizzle-orm/app/routes/_index.tsx index 5c78a49e..9751ba80 100644 --- a/drizzle-orm/app/routes/_index.tsx +++ b/drizzle-orm/app/routes/_index.tsx @@ -22,7 +22,7 @@ export async function action({ request }: ActionArgs) { } export async function loader() { - const rowsQuery = db.select().from(example); + const rowsQuery = db.query.example.findMany(); const lastUpdatedQuery = db .select({ updated: sql`MAX(created_at)` })