sayuto
sayuto
DTDrizzle Team
Created by sayuto on 8/7/2024 in #help
Studio + mysql default mode, wrong format related timezone
Thank you so much for your efforts to help me, you are so kind 🙏
48 replies
DTDrizzle Team
Created by sayuto on 8/7/2024 in #help
Studio + mysql default mode, wrong format related timezone
oh, I seeee. that mean this is a issue come from drizzle-orm, right?if I want to handle this, I need to change mysql to utc, right?
48 replies
DTDrizzle Team
Created by sayuto on 8/7/2024 in #help
Studio + mysql default mode, wrong format related timezone
as I understand, in db, timezone only meaning it will auto parse when select query. because when I do not set TZ db return 2024-08-04 09:42:20 studio return 2024-08-04T02:42:20.000Z this is correct -> I think data in db is correct and it saved as UTC, only when we select data, it will parse by "tool" timezone
48 replies
DTDrizzle Team
Created by sayuto on 8/7/2024 in #help
Studio + mysql default mode, wrong format related timezone
I edited data return for more clear
48 replies
DTDrizzle Team
Created by sayuto on 8/7/2024 in #help
Studio + mysql default mode, wrong format related timezone
my system in +7 GMT
48 replies
DTDrizzle Team
Created by sayuto on 8/7/2024 in #help
Studio + mysql default mode, wrong format related timezone
db: SYSTEM data: 2024-08-04 09:42:20 without TZ=UTC backend: null Data: 2024-08-04T09:42:20.000Z with TZ=UTC backend: UTC data: 2024-08-04T09:42:20.000Z
48 replies
DTDrizzle Team
Created by sayuto on 8/7/2024 in #help
Studio + mysql default mode, wrong format related timezone
I don't think data in mysql is wrong, because I tried with insert data by mysq-cli, it still return the same result
48 replies
DTDrizzle Team
Created by sayuto on 8/7/2024 in #help
Studio + mysql default mode, wrong format related timezone
createdAt alway create by the system, I don't set it
48 replies
DTDrizzle Team
Created by sayuto on 8/7/2024 in #help
Studio + mysql default mode, wrong format related timezone
@Raphaël M (@rphlmr) ⚡ but my problem is the data that get from database was parse to my system timezone, then return as iso string format it was return 2024-08-04T09:42:20.000Z while correct is 2024-08-04T02:42:20.000Z if it want to show it in iso string even I set TZ=UTC, it still return 2024-08-04T09:42:20.000Z loook like timezone do not effect to drizzle-orm timestamp?
48 replies
DTDrizzle Team
Created by sayuto on 8/7/2024 in #help
Studio + mysql default mode, wrong format related timezone
@Raphaël M (@rphlmr) ⚡ I dont set timezone for db/backend/studio -> all will run by default db will auto parse timestamp when we query and yeah, it show correct time based on my system timezone studio show timestamp as iso string in utc backend show timestamp as iso string in my system timezone -> this is the problem. when I set TZ=UTC studio show timestamp as ios string in my system timezone -> wrong backend still show timestamp as ios string in my system timezone -> wrong I can make sure my env was effect because I tryed logger.info(new Date()) on backend and it return correct time by TZ that was setted
48 replies
DTDrizzle Team
Created by sayuto on 8/7/2024 in #help
Studio + mysql default mode, wrong format related timezone
I do not set the timezone for both, just let it run as default. if I set env TZ=UTC, data in the studio will change but the backend will still show as before, I do not see any config related to timezone on drizzle-orm
48 replies
DTDrizzle Team
Created by sayuto on 8/7/2024 in #help
Studio + mysql default mode, wrong format related timezone
@Raphaël M (@rphlmr) ⚡
For the rest it is expected to work like that. In date mode, it’s always serialized in isoString
but as I understand, it's returning wrong data right now, on backend, for me, it returns 2024-08-04T09:42:20.000Z when it should 2024-08-04T02:42:20.000Z if it wants to show in isoString
48 replies
DTDrizzle Team
Created by sayuto on 8/7/2024 in #help
Studio + mysql default mode, wrong format related timezone
@Raphaël M (@rphlmr) ⚡ it mean have no config to fix this issue right now? I need to handle it manually and wait for a fix in the future?
48 replies
DTDrizzle Team
Created by sayuto on 8/7/2024 in #help
Studio + mysql default mode, wrong format related timezone
@Raphaël M (@rphlmr) ⚡ in your image i see you have the same problem with me. created_at and created_at_3 are returning time according to system timezone but still have T and Z inside in backend side. 9:xx on backend 7:xx on studio
48 replies
DTDrizzle Team
Created by sayuto on 8/7/2024 in #help
Studio + mysql default mode, wrong format related timezone
@Raphaël M (@rphlmr) ⚡ - mysql-cli correct - studio will show based on env TZ, if I don't set env, it will show correct data in UTC, if I set env, it will show data based on env TZ but still include T and Z -> wrong format - backend will show wrong because it alway convert data to time in system timezone but still include T and Z in format, and the result is 2024-08-04T09:42:20.000Z -> this thing make Date or Moment think that string is UTC
48 replies
DTDrizzle Team
Created by sayuto on 8/7/2024 in #help
Studio + mysql default mode, wrong format related timezone
@Raphaël M (@rphlmr) ⚡ thank you for your replay, right now, do we have any solution for it? or I need to handle the format manually?
48 replies
DTDrizzle Team
Created by sayuto on 8/6/2024 in #help
DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB typ
@Mario564 thank you, you save my project 🤝
9 replies
DTDrizzle Team
Created by sayuto on 8/6/2024 in #help
DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB typ
@singgih I was defined types like this
import type { MySqlDatabase } from 'drizzle-orm/mysql-core';
import { drizzle as drizzleMysql } from 'drizzle-orm/mysql2';
import { migrate as migrateMysql } from 'drizzle-orm/mysql2/migrator';
import { createConnection } from 'mysql2';
import { PHASE_PRODUCTION_BUILD } from 'next/dist/shared/lib/constants';

import * as schema from '@/models';

import { Env } from './Env';

let connection;
let drizzle: MySqlDatabase<any, any, any>;

if (
process.env.NEXT_PHASE !== PHASE_PRODUCTION_BUILD &&
process.env.NODE_ENV === 'production' &&
Env.DATABASE_URL
) {
connection = await createConnection({
uri: Env.DATABASE_URL,
});

drizzle = drizzleMysql(connection, { schema, mode: 'default' });

await migrateMysql(drizzle, { migrationsFolder: './migrations' });
} else {
const global = globalThis as unknown as { connection: any };

if (!global.connection) {
global.connection = await createConnection({
...
});
}

drizzle = drizzleMysql(global.connection, { schema, mode: 'default' });
await migrateMysql(drizzle, { migrationsFolder: './migrations' });
}

export const db = drizzle;
import type { MySqlDatabase } from 'drizzle-orm/mysql-core';
import { drizzle as drizzleMysql } from 'drizzle-orm/mysql2';
import { migrate as migrateMysql } from 'drizzle-orm/mysql2/migrator';
import { createConnection } from 'mysql2';
import { PHASE_PRODUCTION_BUILD } from 'next/dist/shared/lib/constants';

import * as schema from '@/models';

import { Env } from './Env';

let connection;
let drizzle: MySqlDatabase<any, any, any>;

if (
process.env.NEXT_PHASE !== PHASE_PRODUCTION_BUILD &&
process.env.NODE_ENV === 'production' &&
Env.DATABASE_URL
) {
connection = await createConnection({
uri: Env.DATABASE_URL,
});

drizzle = drizzleMysql(connection, { schema, mode: 'default' });

await migrateMysql(drizzle, { migrationsFolder: './migrations' });
} else {
const global = globalThis as unknown as { connection: any };

if (!global.connection) {
global.connection = await createConnection({
...
});
}

drizzle = drizzleMysql(global.connection, { schema, mode: 'default' });
await migrateMysql(drizzle, { migrationsFolder: './migrations' });
}

export const db = drizzle;
9 replies
DTDrizzle Team
Created by sayuto on 8/6/2024 in #help
DrizzleTypeError<"Seems like the schema generic is missing - did you forget to add it to your DB typ
up
9 replies