Skip to content

Commit f56e1a8

Browse files
committed
feature: planetscale db supported add
1 parent 9556795 commit f56e1a8

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

src/configs/databases/mysql.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@ const MySQLlDatabasesConfigs = [
88
},
99
packages: ['drizzle-orm', 'mysql2', 'dotenv', 'drizzle-kit -D'],
1010
},
11+
{
12+
name: 'PlanetScale',
13+
path: 'planetscale',
14+
template_path: 'templates/mysql/planetscale',
15+
env_var: {
16+
DATABASE_HOST: '',
17+
DATABASE_USERNAME: '',
18+
DATABASE_PASSWORD: '',
19+
DATABASE_URL: '',
20+
},
21+
packages: ['drizzle-orm', '@planetscale/database', 'dotenv', 'drizzle-kit -D'],
22+
},
1123
]
1224

1325
export function getMySQLlDatabasesConfigs() {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import 'dotenv/config'
2+
import { drizzle } from 'drizzle-orm/planetscale-serverless'
3+
4+
const db = drizzle({
5+
connection: {
6+
host: process.env.DATABASE_HOST!,
7+
username: process.env.DATABASE_USERNAME!,
8+
password: process.env.DATABASE_PASSWORD!,
9+
},
10+
})
11+
12+
export default db
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { int, mysqlTable, serial, varchar } from 'drizzle-orm/mysql-core'
2+
3+
export const usersTable = mysqlTable('users_table', {
4+
id: serial().primaryKey(),
5+
name: varchar({ length: 255 }).notNull(),
6+
age: int().notNull(),
7+
email: varchar({ length: 255 }).notNull().unique(),
8+
})
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import 'dotenv/config'
2+
import { defineConfig } from 'drizzle-kit'
3+
4+
export default defineConfig({
5+
out: './drizzle',
6+
schema: '{{path}}/schema.ts',
7+
dialect: 'mysql',
8+
dbCredentials: {
9+
url: process.env.DATABASE_URL!,
10+
},
11+
})

0 commit comments

Comments
 (0)