metowo
metowo
DTDrizzle Team
Created by metowo on 7/14/2024 in #help
db.query returns empty object
thanks
12 replies
DTDrizzle Team
Created by metowo on 7/14/2024 in #help
db.query returns empty object
const { mysqlSchema, int, text } = require('drizzle-orm/mysql-core');
const mysql = require('mysql2/promise');
require('dotenv').config();
const { drizzle } = require('drizzle-orm/mysql2');

const connection = mysql.createConnection({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
charset: 'utf8',
});

const mySchema = mysqlSchema('my_schema');
const mySchemaUsers = mySchema.table('users', {
id: int('id').primaryKey().autoincrement(),
name: text('name'),
});

module.exports = connection
.then(
async (conn) =>
await drizzle(conn, {
schema: { ...mySchemaUsers },
mode: 'default',
})
)
.then((db) => console.log('schema>>', db) || db);
const { mysqlSchema, int, text } = require('drizzle-orm/mysql-core');
const mysql = require('mysql2/promise');
require('dotenv').config();
const { drizzle } = require('drizzle-orm/mysql2');

const connection = mysql.createConnection({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
charset: 'utf8',
});

const mySchema = mysqlSchema('my_schema');
const mySchemaUsers = mySchema.table('users', {
id: int('id').primaryKey().autoincrement(),
name: text('name'),
});

module.exports = connection
.then(
async (conn) =>
await drizzle(conn, {
schema: { ...mySchemaUsers },
mode: 'default',
})
)
.then((db) => console.log('schema>>', db) || db);
is how I updated it
12 replies
DTDrizzle Team
Created by metowo on 7/14/2024 in #help
db.query returns empty object
I also tried to eliminate the potential issue of it being import related by having everything in the same file and I'm still seeing the same thing
12 replies
DTDrizzle Team
Created by metowo on 7/14/2024 in #help
db.query returns empty object
this is what I get when I log db
MySqlDatabase {
query: {},
dialect: MySqlDialect {},
session: MySql2Session {
dialect: MySqlDialect {},
logger: NoopLogger {},
mode: 'default',
client: PromiseConnection {
_events: [Object: null prototype],
_eventsCount: 2,
_maxListeners: undefined,
connection: [Connection],
Promise: [Function: Promise],
[Symbol(shapeMode)]: false,
[Symbol(kCapture)]: false
},
schema: { fullSchema: [Object], schema: {}, tableNamesMap: {} },
options: { logger: undefined, mode: 'default' }
},
mode: 'default',
_: {
schema: {},
fullSchema: {
id: [MySqlInt],
name: [MySqlText],
[Symbol(drizzle:Name)]: 'users',
[Symbol(drizzle:OriginalName)]: 'users',
[Symbol(drizzle:Schema)]: 'my_schema',
[Symbol(drizzle:Columns)]: [Object],
[Symbol(drizzle:ExtraConfigColumns)]: [Object],
[Symbol(drizzle:BaseName)]: 'users',
[Symbol(drizzle:IsAlias)]: false,
[Symbol(drizzle:ExtraConfigBuilder)]: undefined,
[Symbol(drizzle:MySqlInlineForeignKeys)]: []
},
tableNamesMap: {}
}
}
MySqlDatabase {
query: {},
dialect: MySqlDialect {},
session: MySql2Session {
dialect: MySqlDialect {},
logger: NoopLogger {},
mode: 'default',
client: PromiseConnection {
_events: [Object: null prototype],
_eventsCount: 2,
_maxListeners: undefined,
connection: [Connection],
Promise: [Function: Promise],
[Symbol(shapeMode)]: false,
[Symbol(kCapture)]: false
},
schema: { fullSchema: [Object], schema: {}, tableNamesMap: {} },
options: { logger: undefined, mode: 'default' }
},
mode: 'default',
_: {
schema: {},
fullSchema: {
id: [MySqlInt],
name: [MySqlText],
[Symbol(drizzle:Name)]: 'users',
[Symbol(drizzle:OriginalName)]: 'users',
[Symbol(drizzle:Schema)]: 'my_schema',
[Symbol(drizzle:Columns)]: [Object],
[Symbol(drizzle:ExtraConfigColumns)]: [Object],
[Symbol(drizzle:BaseName)]: 'users',
[Symbol(drizzle:IsAlias)]: false,
[Symbol(drizzle:ExtraConfigBuilder)]: undefined,
[Symbol(drizzle:MySqlInlineForeignKeys)]: []
},
tableNamesMap: {}
}
}
12 replies
DTDrizzle Team
Created by metowo on 7/14/2024 in #help
db.query returns empty object
this is the more complete setup: schema.js
const { mysqlSchema, int, varchar, text } = require('drizzle-orm/mysql-core');

const mySchema = mysqlSchema('schema');

const users = mySchema.table('users', {
id: int('id').primaryKey().autoincrement(),
username: varchar('username', { length: 100 }),
password: varchar('password', { length: 100 }),
});
const { mysqlSchema, int, varchar, text } = require('drizzle-orm/mysql-core');

const mySchema = mysqlSchema('schema');

const users = mySchema.table('users', {
id: int('id').primaryKey().autoincrement(),
username: varchar('username', { length: 100 }),
password: varchar('password', { length: 100 }),
});
when logging mySchema, I get
schema before import> MySqlSchema {
table: [Function: table],
view: [Function: view],
schemaName: 'schema'
}
schema before import> MySqlSchema {
table: [Function: table],
view: [Function: view],
schemaName: 'schema'
}
and config.js
const mysql = require('mysql2/promise');
require('dotenv').config();
const { drizzle } = require('drizzle-orm/mysql2');
const { schema } = require('./schema.js');

const connection = mysql.createConnection({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
charset: 'utf8',
});

module.exports = connection
.then(
async (conn) =>
await drizzle(conn, {
schema,
mode: 'default',
})
)
.then((db) => console.log(db.schema) || db);
const mysql = require('mysql2/promise');
require('dotenv').config();
const { drizzle } = require('drizzle-orm/mysql2');
const { schema } = require('./schema.js');

const connection = mysql.createConnection({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
charset: 'utf8',
});

module.exports = connection
.then(
async (conn) =>
await drizzle(conn, {
schema,
mode: 'default',
})
)
.then((db) => console.log(db.schema) || db);
which does show undefined for db.schema
12 replies
TTCTheo's Typesafe Cult
Created by Elite on 3/24/2024 in #questions
invalid env variables
Have you confirmed that a fresh t3 app is reading the env vars before you start fiddling with neon, etc? I noticed that, Lucia auth, for example, reads .env but nextjs wants .env.local. nextjs docs say they honor .env, but it just didn't work like that for me. I think incrementally introducing changes is the way to go
42 replies