Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add drizzle orm with sqlite #13

Merged
merged 40 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
1ce662d
chore: added drizzle and sqlite
aaa006bd Aug 2, 2023
d3e483b
chore: added drizzle config file
aaa006bd Aug 2, 2023
5b9a556
Merge remote-tracking branch 'origin/main' into 12-add-database
aaa006bd Aug 2, 2023
ba94153
chore: added drivers in drizzle config
aaa006bd Aug 3, 2023
99721ae
chore: added databaseInstance
aaa006bd Aug 3, 2023
627e4be
chore: added config for drivers
aaa006bd Aug 3, 2023
d91bdc1
chore: userSchema created
aaa006bd Aug 3, 2023
90f40e7
chore: dbinstance class refactored and exported
aaa006bd Aug 3, 2023
ee494fa
chore: added user type
aaa006bd Aug 3, 2023
0f27b94
chore: added db name in env file
aaa006bd Aug 3, 2023
74821f6
chore: file path config for ts
aaa006bd Aug 3, 2023
1b255a6
chore: installed sqlite3
aaa006bd Aug 3, 2023
50806e5
chore: removed path from tsconfig(causing issue with vite build for n…
aaa006bd Aug 3, 2023
dec56b9
fix: db url for migrations
aaa006bd Aug 3, 2023
673cde4
chore: ignore database file
aaa006bd Aug 3, 2023
a8c5eca
chore: db commands added
aaa006bd Aug 3, 2023
e105d8a
chore: read me updated
aaa006bd Aug 3, 2023
5450812
fix: db name
aaa006bd Aug 3, 2023
c4f509c
chore: added db explorer
aaa006bd Aug 3, 2023
1949861
chore: added pnpm clean
aaa006bd Aug 3, 2023
80e2622
chore: added api to save the user
aaa006bd Aug 3, 2023
55a9567
Merge remote-tracking branch 'origin/main' into 12-add-database
anbraten Aug 4, 2023
1d8b9a7
format code and cleanup db
anbraten Aug 4, 2023
2983e6c
nits
anbraten Aug 4, 2023
14f9e42
adjust drizzle setup
anbraten Aug 4, 2023
dcb9214
chore: removed drizzle studio from gipod startup
aaa006bd Aug 4, 2023
ac58628
fix: insert using run
aaa006bd Aug 4, 2023
82a670c
chore: added migrations
aaa006bd Aug 4, 2023
e7ece0b
add database
aaa006bd Aug 7, 2023
0a4290b
fix: erroneous merge
aaa006bd Aug 7, 2023
03424fa
fix: removed unused code
aaa006bd Aug 7, 2023
463d1d9
fix: added check commands
aaa006bd Aug 7, 2023
d66f2a4
fix: missing dependencies
aaa006bd Aug 7, 2023
0fadb92
fix: added db to prettier ignore
aaa006bd Aug 7, 2023
45a6557
fix: prettier ignore path for db
aaa006bd Aug 7, 2023
15370d4
fix: format
aaa006bd Aug 7, 2023
6d339d7
fix: format
aaa006bd Aug 7, 2023
883fb09
chore: added fix format command
aaa006bd Aug 7, 2023
f1e82f9
remove todo
anbraten Aug 7, 2023
cc7eea1
nits
anbraten Aug 7, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ NUXT_PUBLIC_GITHUB_CLIENT_ID=
NUXT_GITHUB_CLIENT_SECRET=
NUXT_API_URL=
DATA_PATH=./data
DATABASE_NAME=
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ logs
.env
.env.*
!.env.example

# File database

*.db
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Use the command `python uvicorn pyserver:app --reload --app-dir=ai` to start the

[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/geprog/codecaptain)

## Database

We are using Drizzle ORM and sqlite as of now. The schemas need to be inside db/schemas and the migrations will be inside db/migrations. checkout `drizzle.config.ts` for the settings.
use `pnpm push-schema` to directly update the database with new table schemas. This is only intended for development only. Use other commands along with `await migrate(db, { migrationsFolder: "" });` function call in a production environment. More information [https://orm.drizzle.team/kit-docs/quick](here). User `pnpm db-exporer` to open drizzle studio which is in beta state right now.

## ToDo

- [ ] use CodeSplitter and code-detector to get code parts
Expand Down
18 changes: 17 additions & 1 deletion composables/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,27 @@ export const fetchGithubUser = async () => {
export const githubLogin = () => {
if (process.client) {
const { github } = useRuntimeConfig().public;
window.location.replace(`https://github.com/login/oauth/authorize?client_id=${github.clientId}&scope=public_repo`);
window.location.replace(
`https://github.com/login/oauth/authorize?client_id=${github.clientId}&scope=public_repo`
);

}
};

export const githubLogout = async () => {
useGithubCookie().value = null;
useState('gh_user').value = null;
};

export const saveUser = async (user: any) => {
await $fetch('/api/users/save', {
method: 'POST',
body:{
id:user.id,
name: user.name,
loginName: user.login,
avatarUrl : user.avatar_url,
email: user.email
}
})
}
anbraten marked this conversation as resolved.
Show resolved Hide resolved
13 changes: 13 additions & 0 deletions drizzle.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import type { Config } from 'drizzle-kit';

// For config references visit https://orm.drizzle.team/kit-docs/config-reference

export default {
schema: ['./server/**/*.schema.ts'],
out: './server/db/migrations',
dbCredentials: {
url: 'code_captain.db',
},
driver: 'better-sqlite',
breakpoints: true,
} satisfies Config;
30 changes: 18 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,27 @@
"generate": "nuxt generate",
"preview": "nuxt preview",
"postinstall": "nuxt prepare",
"check-format": "prettier --check .",
"typecheck": "tsc --noEmit"
"migrate": "drizzle-kit generate:sqlite",
"drop":"drizzle-kit drop",
"push-schema":"drizzle-kit push:sqlite",
"db-explorer": "drizzle-kit studio",
"clean": "rm -rf dist/ node_modules/ .eslintcache"
},
"devDependencies": {
"@nuxt/devtools": "^0.7.4",
"@nuxtjs/tailwindcss": "^6.8.0",
"@types/node": "^18",
"nuxt": "^3.6.5",
"prettier": "^3.0.1",
"typescript": "^5.1.6"
"@nuxt/devtools": "latest",
"@nuxtjs/tailwindcss": "6.8.0",
"@types/node": "18",
"@types/better-sqlite3": "7.6.4",
"better-sqlite3": "8.5.0",
"drizzle-kit": "^0.19.12",
"nuxt": "3.6.1"
},
"dependencies": {
"nuxt-icon": "^0.4.1",
"octokit": "^2.1.0",
"simple-git": "^3.19.1",
"vue-markdown-render": "^2.0.1"
"better-sqlite3": "8.5.0",
"drizzle-orm": "0.27.2",
"nuxt-icon": "0.4.1",
"octokit": "2.1.0",
"simple-git": "3.19.1",
"vue-markdown-render": "2.0.1"
}
}
Loading
Loading