drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
21.44k stars 484 forks source link

[BUG]: issue while building the project #2497

Closed Moka-admin0 closed 2 weeks ago

Moka-admin0 commented 2 weeks ago

What version of drizzle-orm are you using?

0.31.2

What version of drizzle-kit are you using?

0.22.7

Describe the Bug

after making a build for production it builds successfully, but when you run the porject it faileds,

**ERROR** ReferenceError: int is not defined

inside the build file

// ../src/server/db/schema.ts var ItemStack = mysqlTable("ItemStack", { id: int("id").primaryKey().notNull(), itemId: varchar("itemId", "255").notNull(), variant: varchar("variant", "255"), inventoryId: varchar("inventoryId", "255"), slot: int("slot"), quantity: int("quantity"), decayStartedAt: date("decayStartedAt"), publicMetadata: json("publicMetadata")"default", createdAt: date("createdAt"), updatedAt: date("updatedAt"), hash: varchar("hash", "255"), quality: int("quality"), weight: float("weight") });

Expected behavior

load the script as needed

Environment & setup

tsconfig:

{ "compilerOptions": { "target": "ES2017", "strict": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true, "module": "CommonJS", "types": ["@citizenfx/server", "@types/node"], "lib": ["ES2017"], "baseUrl": "../", "paths": { "@shared/": ["shared/"], } }, "include": ["./*/", "../shared"], "exclude": ["/node_modules", "/tests/*"] }

build.js: == "build:dev": "cd build && node build.js",

const buildServer = async () => { console.log([build] [server] starting build...);

const buildStart = Date.now();

await esbuild.build({
    entryPoints: ['../src/server/server.ts'],
    bundle: true,
    outfile: '../../build/sv_main.js',
    platform: "node",
    plugins: [
        swcPlugin({
            jsc: {
                parser: {
                    syntax: 'typescript',
                    tsx: false,
                    decorators: false,
                    dynamicImport: false
                },
                loose: false,
                externalHelpers: false,
                keepClassNames: false
            },
            env: {
                include: [
                    "transform-async-to-generator",
                    "transform-regenerator"
                ]
            },
            minify: false
        }),
        TsconfigPathsPlugin({
            tsconfig: path.resolve(__dirname, 'src/server/tsconfig.json')
        })
    ]
}).then((result) => {
    if (!shouldObfuscate) {
        const timeTaken = Date.now() - buildStart;
        const timeDisplay = timeTaken < 1000 ? `${timeTaken}ms` : `${timeTaken / 1000}s`;
        return console.log(`[build] [server] build complete | took: ${timeDisplay}`);
    }

    const bundleContent = fs.readFileSync('../../build/sv_main.js', 'utf8');
    const filePath = path.resolve(__dirname, '../../build/sv_main.js');

    // const obfuscationStart = Date.now();

    const obfuscatedCode = obfuscator.obfuscate(bundleContent, {
        compact: true,
        debugProtection: false,
        debugProtectionInterval: false,
        disableConsoleOutput: false,
        identifierNamesGenerator: 'hexadecimal',
        log: false,
        numbersToExpressions: true,
        renameGlobals: false,
        selfDefending: true,
        simplify: true,
        splitStrings: true,
        splitStringsChunkLength: 5,
        stringArray: true,
        stringArrayCallsTransform: true,
        stringArrayCallsTransformThreshold: 1,
        stringArrayEncoding: ['rc4'],
        stringArrayIndexShift: true,
        stringArrayRotate: true,
        stringArrayShuffle: true,
        stringArrayWrappersCount: 15,
        stringArrayWrappersChainedCalls: true,
        stringArrayWrappersParametersMaxCount: 15,
        stringArrayWrappersType: 'function',
        stringArrayThreshold: 1,
        transformObjectKeys: false,
        unicodeEscapeSequence: false
    }).getObfuscatedCode();

    fs.writeFileSync(filePath, obfuscatedCode);

    // console.log(`[build] [server] obfuscation complete | took: ${(Date.now() - obfuscationStart) / 1000}s`);

    const timeTaken = Date.now() - buildStart;
    const timeDisplay = timeTaken < 1000 ? `${timeTaken}ms` : `${timeTaken / 1000}s`;

    console.log(`[build] [server] build and obfuscation complete | took: ${timeDisplay}`);
});

};

Moka-admin0 commented 2 weeks ago

NVM you must do this:

import * as sql from "drizzle-orm/mysql-core";

export const ItemStack = sql.mysqlTable("ItemStack", {
    id: sql.varchar('id', {length: 255}).notNull(),
    itemId: sql.varchar('itemId', {length: 255}).notNull(),
    variant: sql.varchar('variant', {length: 255}),
    inventoryId: sql.varchar('inventoryId', {length: 255}),
    slot: sql.int('slot'),
    quantity: sql.int('quantity'),
    decayStartedAt: sql.date('decayStartedAt'),
    publicMetadata: sql.json('publicMetadata').default("{}"),
    createdAt: sql.date('createdAt'),
    updatedAt: sql.date('updatedAt'),
    hash: sql.varchar('hash', {length: 255}),
    quality: sql.int('quality'),
    weight: sql.float('weight')
});