first commit
commit
6bd7c32a8a
@ -0,0 +1,169 @@
|
||||
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore
|
||||
|
||||
# Logs
|
||||
|
||||
logs
|
||||
_.log
|
||||
npm-debug.log_
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
|
||||
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
||||
|
||||
# Runtime data
|
||||
|
||||
pids
|
||||
_.pid
|
||||
_.seed
|
||||
\*.pid.lock
|
||||
|
||||
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||
|
||||
lib-cov
|
||||
|
||||
# Coverage directory used by tools like istanbul
|
||||
|
||||
coverage
|
||||
\*.lcov
|
||||
|
||||
# nyc test coverage
|
||||
|
||||
.nyc_output
|
||||
|
||||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
|
||||
|
||||
.grunt
|
||||
|
||||
# Bower dependency directory (https://bower.io/)
|
||||
|
||||
bower_components
|
||||
|
||||
# node-waf configuration
|
||||
|
||||
.lock-wscript
|
||||
|
||||
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||
|
||||
build/Release
|
||||
|
||||
# Dependency directories
|
||||
|
||||
node_modules/
|
||||
jspm_packages/
|
||||
|
||||
# Snowpack dependency directory (https://snowpack.dev/)
|
||||
|
||||
web_modules/
|
||||
|
||||
# TypeScript cache
|
||||
|
||||
\*.tsbuildinfo
|
||||
|
||||
# Optional npm cache directory
|
||||
|
||||
.npm
|
||||
|
||||
# Optional eslint cache
|
||||
|
||||
.eslintcache
|
||||
|
||||
# Optional stylelint cache
|
||||
|
||||
.stylelintcache
|
||||
|
||||
# Microbundle cache
|
||||
|
||||
.rpt2_cache/
|
||||
.rts2_cache_cjs/
|
||||
.rts2_cache_es/
|
||||
.rts2_cache_umd/
|
||||
|
||||
# Optional REPL history
|
||||
|
||||
.node_repl_history
|
||||
|
||||
# Output of 'npm pack'
|
||||
|
||||
\*.tgz
|
||||
|
||||
# Yarn Integrity file
|
||||
|
||||
.yarn-integrity
|
||||
|
||||
# dotenv environment variable files
|
||||
|
||||
.env
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
.env.local
|
||||
|
||||
# parcel-bundler cache (https://parceljs.org/)
|
||||
|
||||
.cache
|
||||
.parcel-cache
|
||||
|
||||
# Next.js build output
|
||||
|
||||
.next
|
||||
out
|
||||
|
||||
# Nuxt.js build / generate output
|
||||
|
||||
.nuxt
|
||||
dist
|
||||
|
||||
# Gatsby files
|
||||
|
||||
.cache/
|
||||
|
||||
# Comment in the public line in if your project uses Gatsby and not Next.js
|
||||
|
||||
# https://nextjs.org/blog/next-9-1#public-directory-support
|
||||
|
||||
# public
|
||||
|
||||
# vuepress build output
|
||||
|
||||
.vuepress/dist
|
||||
|
||||
# vuepress v2.x temp and cache directory
|
||||
|
||||
.temp
|
||||
.cache
|
||||
|
||||
# Docusaurus cache and generated files
|
||||
|
||||
.docusaurus
|
||||
|
||||
# Serverless directories
|
||||
|
||||
.serverless/
|
||||
|
||||
# FuseBox cache
|
||||
|
||||
.fusebox/
|
||||
|
||||
# DynamoDB Local files
|
||||
|
||||
.dynamodb/
|
||||
|
||||
# TernJS port file
|
||||
|
||||
.tern-port
|
||||
|
||||
# Stores VSCode versions used for testing VSCode extensions
|
||||
|
||||
.vscode-test
|
||||
|
||||
# yarn v2
|
||||
|
||||
.yarn/cache
|
||||
.yarn/unplugged
|
||||
.yarn/build-state.yml
|
||||
.yarn/install-state.gz
|
||||
.pnp.\*
|
@ -0,0 +1,15 @@
|
||||
# test
|
||||
|
||||
To install dependencies:
|
||||
|
||||
```bash
|
||||
bun install
|
||||
```
|
||||
|
||||
To run:
|
||||
|
||||
```bash
|
||||
bun run index.ts
|
||||
```
|
||||
|
||||
This project was created using `bun init` in bun v1.0.0. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
|
@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "test",
|
||||
"module": "src/main.ts",
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"bun-types": "latest",
|
||||
"drizzle-kit": "^0.19.13"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@bogeychan/elysia-logger": "^0.0.8",
|
||||
"@elysiajs/html": "^0.6.5",
|
||||
"@elysiajs/static": "^0.6.0",
|
||||
"@elysiajs/swagger": "^0.6.2",
|
||||
"@t3-oss/env-core": "^0.6.1",
|
||||
"drizzle-orm": "^0.28.6",
|
||||
"drizzle-typebox": "^0.1.1",
|
||||
"elysia": "^0.6.22",
|
||||
"pino-pretty": "^10.2.0",
|
||||
"zod": "^3.22.2"
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
import { createEnv } from "@t3-oss/env-core";
|
||||
import { z } from "zod";
|
||||
|
||||
export const env = createEnv({
|
||||
server: {
|
||||
LOG_LEVEL: z.enum(["debug", "info", "warn", "error"]),
|
||||
},
|
||||
runtimeEnv: process.env,
|
||||
});
|
@ -0,0 +1,32 @@
|
||||
import { Elysia } from "elysia";
|
||||
import { logger } from "@bogeychan/elysia-logger";
|
||||
import pretty from "pino-pretty";
|
||||
import { html } from "@elysiajs/html";
|
||||
import { env } from "../config";
|
||||
import { db } from "../model/store";
|
||||
|
||||
const stream = pretty({
|
||||
colorize: true,
|
||||
});
|
||||
|
||||
export const ctx = new Elysia({
|
||||
name: "@app/ctx",
|
||||
})
|
||||
.use(
|
||||
logger({
|
||||
level: env.LOG_LEVEL,
|
||||
stream,
|
||||
})
|
||||
)
|
||||
.use(html())
|
||||
.decorate("db", db)
|
||||
.decorate("config", env)
|
||||
.onStart(({ log }) => log.info("Server starting"))
|
||||
.onStop(({ log }) => log.info("Server stopping"))
|
||||
.onRequest(({ log, request }) =>
|
||||
log.debug(`Request received: ${request.method}: ${request.url}`)
|
||||
)
|
||||
.onResponse(({ log, response }) =>
|
||||
log.debug(`Response sent: ${response.statusCode}`)
|
||||
)
|
||||
.onError(({ log, error }) => log.error(error));
|
@ -0,0 +1,24 @@
|
||||
import Elysia from "elysia";
|
||||
import { ctx } from "../context";
|
||||
import { insertTodoSchema } from "../model/todo";
|
||||
import { TodoItem } from "../views/todoItem";
|
||||
|
||||
export const todosController = new Elysia({
|
||||
name: "@app/todos",
|
||||
prefix: "/todos",
|
||||
})
|
||||
.use(ctx)
|
||||
.model({
|
||||
todo: insertTodoSchema,
|
||||
})
|
||||
.get("/", async ({ db }) => {
|
||||
const todos = await db.query.todos.findMany();
|
||||
|
||||
return (
|
||||
<div>
|
||||
{todos.map((todo) => (
|
||||
<TodoItem {...todo} />
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
});
|
@ -0,0 +1,14 @@
|
||||
import { Elysia } from "elysia";
|
||||
import swagger from "@elysiajs/swagger";
|
||||
import { staticPlugin } from "@elysiajs/static";
|
||||
import { todosController } from "./controllers/todos";
|
||||
|
||||
const app = new Elysia({
|
||||
name: "@app/main",
|
||||
})
|
||||
.use(swagger())
|
||||
.use(staticPlugin())
|
||||
.use(todosController)
|
||||
.listen(3000);
|
||||
|
||||
console.log(`app is listening on ${app.server?.hostname}:${app.server?.port}`);
|
@ -0,0 +1 @@
|
||||
export { todos } from "./todo";
|
@ -0,0 +1,6 @@
|
||||
import { drizzle } from "drizzle-orm/bun-sqlite";
|
||||
import { Database } from "bun:sqlite";
|
||||
import * as schema from "../schema";
|
||||
|
||||
const sqlite = new Database("sqlite.db");
|
||||
export const db = drizzle(sqlite, { schema });
|
@ -0,0 +1,14 @@
|
||||
import { text, integer, sqliteTable } from "drizzle-orm/sqlite-core";
|
||||
import { createInsertSchema, createSelectSchema } from "drizzle-typebox";
|
||||
|
||||
export const todos = sqliteTable("todo", {
|
||||
id: integer("id").primaryKey({ autoIncrement: true }),
|
||||
content: text("content").notNull(),
|
||||
done: integer("done", { mode: "boolean" }).notNull().default(false),
|
||||
});
|
||||
|
||||
export type Todo = typeof todos.$inferSelect;
|
||||
export type InsertTodo = typeof todos.$inferInsert;
|
||||
|
||||
export const insertTodoSchema = createInsertSchema(todos);
|
||||
export const selectTodoSchema = createSelectSchema(todos);
|
@ -0,0 +1,10 @@
|
||||
import type { Todo } from "../model/todo";
|
||||
|
||||
export const TodoItem = (todo: Todo) => {
|
||||
return (
|
||||
<li>
|
||||
<input type="checkbox" checked={todo.done} />
|
||||
<span>{todo.content}</span>
|
||||
</li>
|
||||
);
|
||||
};
|
@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"lib": ["ESNext"],
|
||||
"module": "esnext",
|
||||
"target": "esnext",
|
||||
"moduleResolution": "bundler",
|
||||
"moduleDetection": "force",
|
||||
"allowImportingTsExtensions": true,
|
||||
"noEmit": true,
|
||||
"composite": true,
|
||||
"strict": true,
|
||||
"downlevelIteration": true,
|
||||
"skipLibCheck": true,
|
||||
"jsx": "react",
|
||||
"jsxFactory": "ElysiaJSX",
|
||||
"jsxFragmentFactory": "ElysiaJSX.Fragment",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"allowJs": true,
|
||||
"types": [
|
||||
"bun-types" // add Bun global
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue