Prodromos
Prodromos
Explore posts from servers
DTDrizzle Team
Created by Prodromos on 9/26/2024 in #help
The requested module 'node_modules/pg/lib/index.js' does not provide an export named 'Pool'
I try to to setup the drizzle with nuxt but I have an error. All the structure I make down above. Run the npm run dev and the error appear... Error
The requested module 'file:///nuxt-drizzle-example/node_modules/pg/lib/index.js' does not provide an export named 'Pool'

import { Pool } from 'node_modules/pg/lib/index.js';
^^^^
SyntaxError: The requested module 'node_modules/pg/lib/index.js' does not provide an export named 'Pool'
at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)
The requested module 'file:///nuxt-drizzle-example/node_modules/pg/lib/index.js' does not provide an export named 'Pool'

import { Pool } from 'node_modules/pg/lib/index.js';
^^^^
SyntaxError: The requested module 'node_modules/pg/lib/index.js' does not provide an export named 'Pool'
at ModuleJob._instantiate (node:internal/modules/esm/module_job:124:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:190:5)
drizzle.config.ts
import { defineConfig } from 'drizzle-kit'

export default defineConfig({
dialect: 'postgresql',
schema: './server/database/schema.ts',
out: './server/database/migrations',
dbCredentials: {
url: process.env.DATABASE_URL!,
}
})
import { defineConfig } from 'drizzle-kit'

export default defineConfig({
dialect: 'postgresql',
schema: './server/database/schema.ts',
out: './server/database/migrations',
dbCredentials: {
url: process.env.DATABASE_URL!,
}
})
server/utils/drizzle.ts
import { Pool } from "pg"
import { drizzle } from "drizzle-orm/node-postgres"
import * as schema from "../database/schema"

export { sql, eq, and, or, like } from 'drizzle-orm'

export const tables = schema

const pool = new Pool({
connectionString: process.env.DATABASE_URL!,
})

export function useDatabase() {
return drizzle(pool, { schema })
}
import { Pool } from "pg"
import { drizzle } from "drizzle-orm/node-postgres"
import * as schema from "../database/schema"

export { sql, eq, and, or, like } from 'drizzle-orm'

export const tables = schema

const pool = new Pool({
connectionString: process.env.DATABASE_URL!,
})

export function useDatabase() {
return drizzle(pool, { schema })
}
1 replies
DTDrizzle Team
Created by Prodromos on 9/24/2024 in #help
How to connect the relationships between user, roles and permissions?
I try to figure out how to create a tables (user, role and permissions) with relationships and make the an example how to use them.
const users = pgTable("users", {
id: serial("id").primaryKey(),
name: text("name").notNull(),
email: text("email").notNull(),
password: text("password").notNull(),
});

const roles = pgTable("roles", {
id: serial("id").primaryKey(),
name: text("name").notNull(),
});

const permissions = pgTable("permissions", {
id: serial("id").primaryKey(),
name: text("name").notNull(),
});

const usersRelations = relations(users, ({ one, many }) => ({
role: one(roles, {
fields: [users.id],
references: [roles.userId],
}),
permissions: many(permissions, (join) => join.through(userRoles)),
}));
const users = pgTable("users", {
id: serial("id").primaryKey(),
name: text("name").notNull(),
email: text("email").notNull(),
password: text("password").notNull(),
});

const roles = pgTable("roles", {
id: serial("id").primaryKey(),
name: text("name").notNull(),
});

const permissions = pgTable("permissions", {
id: serial("id").primaryKey(),
name: text("name").notNull(),
});

const usersRelations = relations(users, ({ one, many }) => ({
role: one(roles, {
fields: [users.id],
references: [roles.userId],
}),
permissions: many(permissions, (join) => join.through(userRoles)),
}));
1 replies