File tree 6 files changed +29
-7
lines changed
6 files changed +29
-7
lines changed Original file line number Diff line number Diff line change 178
178
179
179
# Finder (MacOS) folder config
180
180
.DS_Store
181
+ bunfig.toml
Original file line number Diff line number Diff line change 1
1
import { Database } from "bun:sqlite" ;
2
2
import { drizzle , type BunSQLiteDatabase } from "drizzle-orm/bun-sqlite" ;
3
3
import * as schema from './schema' ;
4
+ import { logPlugin , logger } from '../utils/logger'
4
5
5
6
let dbInstance : BunSQLiteDatabase < typeof schema > ;
6
7
7
8
const getDbInstance = ( ) => {
8
9
if ( ! dbInstance ) {
9
- console . log ( `Connect to ${ process . env . DB_PATH } ` ) ;
10
+ logger . debug ( `Connect to ${ process . env . DB_PATH } ` ) ;
10
11
const connection = new Database ( process . env . DB_PATH ?? 'sqlite.db' , { create : true } ) ;
11
12
dbInstance = drizzle ( connection , { schema : schema } ) ;
12
13
}
Original file line number Diff line number Diff line change 1
1
import { Database } from "bun:sqlite" ;
2
2
import { drizzle } from "drizzle-orm/bun-sqlite" ;
3
3
import { migrate } from 'drizzle-orm/bun-sqlite/migrator' ;
4
+ import { logger } from '../utils/logger'
4
5
5
6
export async function migration ( ) {
6
7
const start = new Date ( ) . getTime ( ) ;
@@ -11,5 +12,5 @@ export async function migration() {
11
12
await connection . close ( ) ;
12
13
13
14
const end = new Date ( ) . getTime ( ) ;
14
- console . log ( `Migration to ${ db_path } took ${ end - start } ms` ) ;
15
+ logger . debug ( `Migration to ${ db_path } took ${ end - start } ms` ) ;
15
16
}
Original file line number Diff line number Diff line change 1
1
import cors from '@elysiajs/cors' ;
2
2
import { Elysia } from 'elysia' ;
3
- import { Logestic } from 'logestic' ;
4
3
import { PostService } from './action/post' ;
5
4
import { UserService } from './action/user' ;
6
5
import { migration } from './db/migrate' ;
6
+ import { logPlugin , logger } from './utils/logger'
7
7
8
8
migration ( )
9
9
10
- const log = Logestic . preset ( 'fancy' )
11
10
export const app = new Elysia ( )
12
11
. use ( cors ( ) )
13
- . use ( log )
12
+ . use ( logPlugin )
14
13
. use ( UserService )
15
14
. use ( PostService )
16
- . get ( '/' , ( { uid} ) => `Hi ${ uid } ` )
15
+ . get ( '/' , ( { uid } ) => `Hi ${ uid } ` )
17
16
. onError ( ( { code } ) => {
18
17
if ( code === 'NOT_FOUND' )
19
18
return ':('
20
19
} )
21
- . listen ( process . env . PORT ?? 3001 )
20
+ . listen ( process . env . PORT ?? 3001 , ( ) => {
21
+ logger . info ( `[Rim] Server is running: http://localhost:${ process . env . PORT ?? 3001 } ` )
22
+ } )
22
23
23
24
export type App = typeof app
Original file line number Diff line number Diff line change
1
+ /*
2
+ * @Author : Bin
3
+ * @Date : 2024-05-22
4
+ * @FilePath : /oXeu_rin/src/utils/index.ts
5
+ */
6
+
7
+ export * from './logger'
Original file line number Diff line number Diff line change
1
+ /*
2
+ * @Author : Bin
3
+ * @Date : 2024-05-22
4
+ * @FilePath : /oXeu_rin/src/utils/logger.ts
5
+ */
6
+ import { Logestic } from 'logestic' ;
7
+
8
+ const logPlugin = Logestic . preset ( 'fancy' )
9
+ const { logestic : logger } = logPlugin . decorator ;
10
+
11
+ export { logPlugin , logger }
You can’t perform that action at this time.
0 commit comments