Skip to content

Commit

Permalink
feat: add drizzle
Browse files Browse the repository at this point in the history
  • Loading branch information
risv1 committed Oct 24, 2024
1 parent 4df0b70 commit 4b4bab1
Show file tree
Hide file tree
Showing 17 changed files with 121 additions and 75 deletions.
3 changes: 1 addition & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
DB_URL="YOUR_DB_URL"
JWT_SECRET="YOUR_JWT_SECRET"
DB_URL="YOUR_DB_URL"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
.nitro
.cache
dist
*.db
.drizzle

# Node dependencies
node_modules
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ format:
lint:
@bunx biome lint --write ./app ./server

update-deps:
upgrade-deps:
@ncu -u
@bun i
9 changes: 4 additions & 5 deletions app/components/Counter.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<script setup lang="ts">
import { useCount } from '~/store/count';
import { useCount } from "~/store/count";
const counter = useCount();
const buttons = [
{ icon: 'ic:baseline-plus', fn: counter.increment },
{ icon: 'ic:baseline-minus', fn: counter.decrement },
]
{ icon: "ic:baseline-plus", fn: counter.increment },
{ icon: "ic:baseline-minus", fn: counter.decrement },
];
</script>

<template>
Expand Down
60 changes: 30 additions & 30 deletions app/components/Hero.vue
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
<script setup lang="ts">
const icons = [
{
name: 'pinia',
iconName: 'logos:pinia',
label: 'Pinia',
},
{
name: 'drizzle',
iconName: 'simple-icons:drizzle',
label: 'Drizzle ORM',
},
{
name: 'biome',
iconName: 'devicon:biome',
label: 'Biome',
},
{
name: 'docker',
iconName: 'logos:docker-icon',
label: 'Docker',
},
{
name: 'bun',
iconName: 'devicon:bun',
label: 'Bun',
},
{
name: 'unocss',
iconName: 'logos:unocss',
label: 'UnoCSS',
}
{
name: "pinia",
iconName: "logos:pinia",
label: "Pinia",
},
{
name: "drizzle",
iconName: "simple-icons:drizzle",
label: "Drizzle ORM",
},
{
name: "biome",
iconName: "devicon:biome",
label: "Biome",
},
{
name: "docker",
iconName: "logos:docker-icon",
label: "Docker",
},
{
name: "bun",
iconName: "devicon:bun",
label: "Bun",
},
{
name: "unocss",
iconName: "logos:unocss",
label: "UnoCSS",
},
];
</script>

Expand Down
23 changes: 11 additions & 12 deletions app/components/Theme.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
<script setup lang="ts">
const colorMode = useColorMode({
modes: {
light: 'light',
dark: 'dark'
}
})
const isDark = useState('isDark', ()=>true)
modes: {
light: "light",
dark: "dark",
},
});
const isDark = useState("isDark", () => true);
const toggleColorMode = () => {
colorMode.value = colorMode.value === 'light' ? 'dark' : 'light'
isDark.value = !isDark.value
}
colorMode.value = colorMode.value === "light" ? "dark" : "light";
isDark.value = !isDark.value;
};
onMounted(() => {
isDark.value = colorMode.value === 'dark'
})
isDark.value = colorMode.value === "dark";
});
</script>

<template>
Expand Down
12 changes: 7 additions & 5 deletions app/pages/auth.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<script setup lang="ts">
const isLogin = ref(true);
const toggleType = () => {
isLogin.value = !isLogin.value;
}
const toggleText = computed(() => isLogin.value ? 'Already have an account? Login here!' : 'Don\'t have an account? Sign up here!');
isLogin.value = !isLogin.value;
};
const toggleText = computed(() =>
isLogin.value
? "Already have an account? Login here!"
: "Don't have an account? Sign up here!",
);
</script>

<template>
Expand Down
24 changes: 12 additions & 12 deletions app/store/count.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export const useCount = defineStore({
id: 'count',
state: () => ({ count: 0 }),
actions: {
increment() {
this.count++
},
decrement() {
this.count--
},
},
persist: true,
})
id: "count",
state: () => ({ count: 0 }),
actions: {
increment() {
this.count++;
},
decrement() {
this.count--;
},
},
persist: true,
});
Binary file modified bun.lockb
Binary file not shown.
13 changes: 13 additions & 0 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { defineConfig } from "drizzle-kit"
import { dbUrl } from "./env"

export default defineConfig({
schema: "server/database/schema.ts",
out: ".drizzle",
dialect: "sqlite",
dbCredentials: {
url: dbUrl
},
strict: true,
verbose: true
})
5 changes: 5 additions & 0 deletions env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if (!process.env.DB_URL) {
throw new Error('DB_URL is not set in .env file');
}

export const dbUrl = process.env.DB_URL
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@
"@pinia-plugin-persistedstate/nuxt": "^1.2.1",
"@pinia/nuxt": "^0.5.5",
"@types/bcrypt": "^5.0.2",
"@types/better-sqlite3": "^7.6.11",
"@types/jsonwebtoken": "^9.0.7",
"@types/uuid": "^10.0.0",
"@unocss/nuxt": "^0.63.6",
"@vueuse/core": "^11.1.0",
"@vueuse/nuxt": "^11.1.0",
"bcrypt": "^5.1.1",
"better-sqlite3": "^11.5.0",
"class-variance-authority": "^0.7.0",
"drizzle-kit": "^0.26.2",
"drizzle-orm": "^0.35.3",
"drizzle-kit": "0.21",
"drizzle-orm": "0.29.5",
"jsonwebtoken": "^9.0.2",
"lucide-vue-next": "^0.453.0",
"nuxt": "^3.13.2",
Expand All @@ -38,8 +40,7 @@
},
"devDependencies": {
"@biomejs/biome": "1.9.4",
"autoprefixer": "^10.4.20",
"postcss": "^8.4.47",
"tailwindcss": "^3.4.14"
"@types/bun": "^1.1.12",
"bun-types": "^1.1.33"
}
}
3 changes: 3 additions & 0 deletions server/api/health.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default defineEventHandler(() => {
return { "status": "ok" }
})
4 changes: 4 additions & 0 deletions server/database/db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { drizzle } from 'drizzle-orm/better-sqlite3';
import { dbUrl } from '~~/env';

export const db = drizzle(dbUrl);
13 changes: 13 additions & 0 deletions server/database/schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { sql } from "drizzle-orm";
import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";

export const users = sqliteTable("users", {
id: integer("id").primaryKey({ autoIncrement: true }),
name: text("name").notNull(),
email: text("email").notNull().unique(),
password: text("password").notNull(),
created_at: text("timestamp").notNull().default(sql`(current_timestamp)`),
updated_at: text("timestamp").notNull().default(sql`(current_timestamp)`),
deleted_at: text("timestamp"),
is_deleted: integer("is_deleted").notNull().default(0)
})
7 changes: 5 additions & 2 deletions server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "../.nuxt/tsconfig.server.json"
}
"extends": "../.nuxt/tsconfig.server.json",
"compilerOptions": {
"types": ["bun-types"],
}
}
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
// https://nuxt.com/docs/guide/concepts/typescript
"extends": "./.nuxt/tsconfig.json"
"extends": "./.nuxt/tsconfig.json",
"compilerOptions": {
"types": ["bun-types"],
}
}

0 comments on commit 4b4bab1

Please sign in to comment.