Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { config } from "dotenv";
import { defineConfig } from 'drizzle-kit';

config();
config({ path: ['.env.local', '.env'] });

export default defineConfig({
out: "./drizzle",
Expand Down
27 changes: 5 additions & 22 deletions frameworks/react-cra/add-ons/drizzle/assets/src/db/index.ts.ejs
Original file line number Diff line number Diff line change
@@ -1,27 +1,10 @@
import { config } from 'dotenv'
<% if (addOnOption.drizzle.database === 'postgresql') { %>
import { drizzle } from 'drizzle-orm/node-postgres';
import { Pool } from 'pg';
import { drizzle } from <% if (addOnOption.drizzle.database === 'postgresql') { %>
'drizzle-orm/node-postgres';
<% } else if (addOnOption.drizzle.database === 'mysql') {%>
import { drizzle } from 'drizzle-orm/mysql2';
import mysql from 'mysql2/promise';
'drizzle-orm/mysql2';
<% } else if (addOnOption.drizzle.database === 'sqlite') {%>
import { drizzle } from 'drizzle-orm/better-sqlite3';
import Database from 'better-sqlite3';
'drizzle-orm/better-sqlite3';
<% } %>
import * as schema from './schema.ts'

config()

<% if (addOnOption.drizzle.database === 'sqlite') { %>
const sqlite = new Database(process.env.DATABASE_URL!);
export const db = drizzle(sqlite, { schema });
<% } else if (addOnOption.drizzle.database === 'postgresql') { %>
const pool = new Pool({
connectionString: process.env.DATABASE_URL!,
});
export const db = drizzle(pool, { schema });
<% } else if (addOnOption.drizzle.database === 'mysql') { %>
const connection = await mysql.createConnection(process.env.DATABASE_URL!);
export const db = drizzle(connection, { schema });
<% } %>
export const db = drizzle(process.env.DATABASE_URL!, { schema<% if (addOnOption.drizzle.database === 'mysql') {%>, mode: 'default'<% } %>});
12 changes: 6 additions & 6 deletions frameworks/react-cra/add-ons/drizzle/assets/src/db/schema.ts.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { pgTable, serial, text, timestamp } from
'drizzle-orm/pg-core';

export const todos = pgTable('todos', {
id: serial('id').primaryKey(),
title: text('title').notNull(),
id: serial().primaryKey(),
title: text().notNull(),
createdAt: timestamp('created_at').defaultNow(),
});
<% } else if (addOnOption.drizzle.database === 'mysql') {
Expand All @@ -13,8 +13,8 @@ import { mysqlTable, int, text, timestamp } from
'drizzle-orm/mysql-core';

export const todos = mysqlTable('todos', {
id: int('id').primaryKey().autoincrement(),
title: text('title').notNull(),
id: int().primaryKey().autoincrement(),
title: text().notNull(),
createdAt: timestamp('created_at', { mode: 'date' }).defaultNow(),
});
<% } else if (addOnOption.drizzle.database === 'sqlite') {
Expand All @@ -24,9 +24,9 @@ import { sqliteTable, integer, text } from
import { sql } from 'drizzle-orm';

export const todos = sqliteTable('todos', {
id: integer('id', { mode: 'number' }).primaryKey({
id: integer({ mode: 'number' }).primaryKey({
autoIncrement: true }),
title: text('title').notNull(),
title: text().notNull(),
createdAt: integer('created_at', { mode: 'timestamp' }).default(sql`(unixepoch())`),
});
<% } %>
16 changes: 7 additions & 9 deletions frameworks/react-cra/add-ons/drizzle/package.json.ejs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
{
"dependencies": {
"drizzle-orm": "^0.39.0",
"drizzle-kit": "^0.30.0"<% if (addOnOption.drizzle.database === 'postgresql') { %>,
"pg": "^8.11.0"<% } %><% if (addOnOption.drizzle.database === 'mysql') { %>,
"mysql2": "^3.6.0"<% } %><% if (addOnOption.drizzle.database === 'sqlite') { %>,
"better-sqlite3": "^9.4.0"<% } %>
"drizzle-orm": "^0.45.0",
"drizzle-kit": "^0.31.8"<% if (addOnOption.drizzle.database === 'postgresql') { %>,
"pg": "^8.16.3"<% } %><% if (addOnOption.drizzle.database === 'mysql') { %>,
"mysql2": "^3.15.3"<% } %><% if (addOnOption.drizzle.database === 'sqlite') { %>,
"better-sqlite3": "^12.5.0"<% } %>
},
"devDependencies": {
"dotenv": "^16.0.0",
"tsx": "^4.0.0",
<% if (addOnOption.drizzle.database === 'postgresql') { %>
"@types/pg": "^8.10.0"<% } %><% if (addOnOption.drizzle.database === 'mysql') { %>
"@types/mysql2": "^3.6.0"<% } %><% if (addOnOption.drizzle.database === 'sqlite') { %>
"tsx": "^4.0.0"<% if (addOnOption.drizzle.database === 'postgresql') { %>,
"@types/pg": "^8.15.6"<% } %><% if (addOnOption.drizzle.database === 'sqlite') { %>,
"@types/better-sqlite3": "^7.6.0"<% } %>
},
"scripts": {
Expand Down