dev-resources.site
for different kinds of informations.
Sveltekit + TypeScript + TypeORM + ESM
SvelteKit Project ์์ฑ
npm create svelte@latest test1
# Skeleton project
# using TypeScript
# check ESLint, Prettier, Playwright, Vitest
cd test1
bun i
TypeORM ์ค์
์ฐธ์กฐ: https://typeorm.io/#installation
bun add typeorm reflect-metadata pg
bun add @types/node tsx -d
tsconfig.json
"compilerOptions": {
...
"emitDecoratorMetadata": true,
"experimentalDecorators": true
}
package.json
"scripts": {
...
"typeorm": "tsx ./node_modules/typeorm/cli.js --dataSource src/lib/typeorm/config.ts",
"migration:create": "tsx ./node_modules/typeorm/cli.js migration:create src/lib/typeorm/migrations/Migration",
"migration:generate": "npm run typeorm migration:generate src/lib/typeorm/migrations/Migration",
"migration:run": "npm run typeorm migration:run"
}
src/lib/typeorm/config.ts
import { DataSource } from 'typeorm';
export const AppDataSource = new DataSource({
type: 'postgres',
host: 'localhost',
port: 5432,
username: 'postgres',
password: 'default_password',
database: 'postgres',
synchronize: false,
logging: true,
entities: ['src/lib/typeorm/entity/*.ts'],
subscribers: [],
migrations: ['src/lib/typeorm/migrations/*.ts']
});
ํ ์คํธ
npm run migration:create
์ด๋ ๊ฒํ๋ TypeORM ์์ migration์ด๋ CRUD์์ Unknown file extension ".ts"
๊ฐ ๋ฐ์ํ๋ค.
์๋ฌด๋ฆฌ ์ฐพ์๋ด๋ ํด๋ต์ ์๋ ๊ฒ ๊ฐ๊ณ , ์ด๋ ๊ฒ ํ๋๊ฒ ์ต์ ์ธ ๊ฒ ๊ฐ๋ค.
src/lib/typeorm/config.ts
import { User } from './entity/User';
import { Company } from './entity/Company';
...
entities: [User, Company],
migrations: ['dist/lib/typeorm/migrations/*.{ts, js}']
...
๊ฒฐ๊ตญ์ ํด๊ฒฐํ์ง ๋ชปํ๋ค. ๋ค๋ฅธ Prisma, Sequelize, MikroORM, DrizzleORM ์ ๋ชจ๋ ํ์ธํด๋ดค์ง๋ง, TypeORM๋งํผ ๋ง์ด๊ทธ๋ ์ด์
์ฉ์ผ๋ก ๊ด์ฐฎ์ ๊ฑด ์๋ ๊ฒ ๊ฐ๊ณ (๊ทธ๋๋ง MikroORM์ด ๊ฐ์ฅ ๊ทผ์ ํ๋ค), ๊ฒฐ๊ตญ ๋ง์ด๊ทธ๋ ์ด์
์ TypeORM์ผ๋ก, ๊ทธํ์ Drizzle์ db:pull
๋ก ๊ฐ์ ธ์จ ํ CRUD๋ Drizzle์ ์ฌ์ฉํ๊ธฐ๋ก ํ๋ค.
migrations: ['src/lib/typeorm/migrations/*.ts']
์ด ๋ถ๋ถ์ ํ์์๋ ์ฃผ์์ฒ๋ฆฌ๋ฅผ ํด๋๊ณ ๋ง์ด๊ทธ๋ ์ด์
ํ ๋๋ง ํด์ ํด์ ์ฌ์ฉํ๋ ๊ฑธ๋ก ์ฌ์ฉ ์ค์ด๋ค. drizzle์ ์ ๊ฑฐ ํ๋ค.
config.ts
์ config.migration.ts
๋ก ๋๋ ์, package.json
๋ฃ๋ ์ ๋ณด๋ ๋ง์ด๊ทธ๋ ์ด์
์์๋ง ์ฌ์ฉํ๋ config.migration.ts
๋ก ๋ฑ๋กํ๊ณ , ์ค์ ์ฝ๋๋ config.ts
๋ฅผ ์ฌ์ฉํ๊ณ ์๋ค.
Featured ones: