Skip to content

Commit

Permalink
feat: 初始化数据库
Browse files Browse the repository at this point in the history
  • Loading branch information
ikxin committed Jan 26, 2024
1 parent c5f1e01 commit e141390
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
.DS_Store
node_modules
dist
sqlite.db
drizzle
Binary file modified bun.lockb
Binary file not shown.
14 changes: 14 additions & 0 deletions db/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { text, integer, sqliteTable } from 'drizzle-orm/sqlite-core'

export const domain = sqliteTable('domain', {
id: integer('id').primaryKey({ autoIncrement: true }),
domain: text('domain').unique().notNull(),
})

export const log = sqliteTable('log', {
id: integer('id').primaryKey({ autoIncrement: true }),
domainId: integer('domain_id').references(() => domain.id),
delay: integer('delay', { mode: 'number' }),
status: integer('status', { mode: 'boolean' }),
timestamp: integer('timestamp', { mode: 'timestamp_ms' }),
})
5 changes: 5 additions & 0 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { Config } from 'drizzle-kit'
export default {
schema: './db/schema.ts',
out: './db/drizzle',
} satisfies Config
9 changes: 9 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { drizzle } from 'drizzle-orm/bun-sqlite'
import { migrate } from 'drizzle-orm/bun-sqlite/migrator'
import { Database } from 'bun:sqlite'
import * as schema from './db/schema'

const sqlite = new Database('./db/sqlite.db')
const db = drizzle(sqlite, { schema })

migrate(db, { migrationsFolder: './db/drizzle' })
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
"author": "一纸忘忧 <i@ikxin.com>",
"type": "module",
"scripts": {
"build": "bun x vite build",
"dev": "bun x vite",
"service": "bun --watch service/server.ts",
"tsc": "bun x vue-tsc"
"build": "vite build",
"dev": "vite",
"service": "bun --watch index.ts",
"generate": "drizzle-kit generate:sqlite",
"tsc": "vue-tsc"
},
"dependencies": {
"@arco-design/web-vue": "^2.54.1",
Expand All @@ -32,6 +33,8 @@
"@typescript-eslint/eslint-plugin": "^6.17.0",
"@typescript-eslint/parser": "^6.17.0",
"@vitejs/plugin-vue": "^5.0.2",
"drizzle-kit": "^0.20.13",
"drizzle-orm": "^0.29.3",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-vue": "^9.19.2",
Expand Down

0 comments on commit e141390

Please sign in to comment.