Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql-drizzle build error #4125

Open
mfukushim opened this issue Dec 12, 2024 · 7 comments
Open

sql-drizzle build error #4125

mfukushim opened this issue Dec 12, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@mfukushim
Copy link

What version of Effect is running?

3.11.5

What steps can reproduce the bug?

Hello, I am trying to build a small app using Effect and drizzle but I keep getting build errors. I tried to make a small app with Effect and drizzle but i get build errors.

A simple way to reproduce

  1. Build the basic app with “pnpm create effect-app@latest”.
  2. Replace the contents of src/Program.ts with effect git packages/sql-drizzle/examples/sqlite.ts
  3. "pnpm install @effect/sql @effect/sql-drizzle @effect/sql-sqlite-node [email protected]" to add missing packages
  4. pnpm run build
  5. I get the following TS2379 and TS2345 errors
src/Program.ts:28:20 - error TS2379: Argument of type 'SQLiteTableWithColumns<{ name: "users"; schema: undefined; columns: { id: SQLiteColumn<{ name: "id"; tableName: "users"; dataType
: "number"; columnType: "SQLiteInteger"; data: number; driverParam: number; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, object>; name: SQLiteColumn<...>; ...' is not assignable to parameter of type 'SQLiteTable<TableConfig>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
  The types of '_.config.columns' are incompatible between these types.
    Type '{ id: SQLiteColumn<{ name: "id"; tableName: "users"; dataType: "number"; columnType: "SQLiteInteger"; data: number; driverParam: number; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, object>; name: SQLiteColumn<...>; }' is not assignable to type 'Record<string, SQLiteColumn<any, object>>'.
      Property 'id' is incompatible with index signature.
        Type 'SQLiteColumn<{ name: "id"; tableName: "users"; dataType: "number"; columnType: "SQLiteInteger"; data: number; driverParam: number; notNull: true; hasDefault: true; enumVa
lues: undefined; baseColumn: never; }, object>' is not assignable to type 'SQLiteColumn<any, object>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
          The types of 'table._.config.columns' are incompatible between these types.
            Type 'Record<string, import("D:/mfuku/Documents/projects/scratchProj/effect_sample2/node_modules/.pnpm/[email protected][email protected]/node_modules/drizzle-orm/sql
ite-core/columns/common", { with: { "resolution-mode": "import" } }).SQLiteColumn<any, object>>' is not assignable to type 'Record<string, import("D:/mfuku/Documents/projects/scratchProj/effect_sample2/node_modules/.pnpm/[email protected][email protected]/node_modules/drizzle-orm/sqlite-core/columns/common").SQLiteColumn<any, object>>'.
              'string' index signatures are incompatible.
                Type 'import("D:/mfuku/Documents/projects/scratchProj/effect_sample2/node_modules/.pnpm/[email protected][email protected]/node_modules/drizzle-orm/sqlite-core/co
lumns/common", { with: { "resolution-mode": "import" } }).SQLiteColumn<any, object>' is not assignable to type 'import("D:/mfuku/Documents/projects/scratchProj/effect_sample2/node_modu
les/.pnpm/[email protected][email protected]/node_modules/drizzle-orm/sqlite-core/columns/common").SQLiteColumn<any, object>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
                  Property 'config' is protected but type 'Column<T, TRuntimeConfig, TTypeConfig>' is not a class derived from 'Column<T, TRuntimeConfig, TTypeConfig>'.

28   yield* db.delete(users)
                      ~~~~~

src/Program.ts:29:20 - error TS2379: Argument of type 'SQLiteTableWithColumns<{ name: "users"; schema: undefined; columns: { id: SQLiteColumn<{ name: "id"; tableName: "users"; dataType
: "number"; columnType: "SQLiteInteger"; data: number; driverParam: number; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, object>; name: SQLiteColumn<...>; ...' is not assignable to parameter of type 'SQLiteTable<TableConfig>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
  The types of '_.config.columns' are incompatible between these types.
    Type '{ id: SQLiteColumn<{ name: "id"; tableName: "users"; dataType: "number"; columnType: "SQLiteInteger"; data: number; driverParam: number; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, object>; name: SQLiteColumn<...>; }' is not assignable to type 'Record<string, SQLiteColumn<any, object>>'.
      Property 'id' is incompatible with index signature.
        Type 'SQLiteColumn<{ name: "id"; tableName: "users"; dataType: "number"; columnType: "SQLiteInteger"; data: number; driverParam: number; notNull: true; hasDefault: true; enumVa
lues: undefined; baseColumn: never; }, object>' is not assignable to type 'SQLiteColumn<any, object>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
          The types of 'table._.config.columns' are incompatible between these types.
            Type 'Record<string, import("D:/mfuku/Documents/projects/scratchProj/effect_sample2/node_modules/.pnpm/[email protected][email protected]/node_modules/drizzle-orm/sql
ite-core/columns/common", { with: { "resolution-mode": "import" } }).SQLiteColumn<any, object>>' is not assignable to type 'Record<string, import("D:/mfuku/Documents/projects/scratchProj/effect_sample2/node_modules/.pnpm/[email protected][email protected]/node_modules/drizzle-orm/sqlite-core/columns/common").SQLiteColumn<any, object>>'.
              'string' index signatures are incompatible.
                Type 'import("D:/mfuku/Documents/projects/scratchProj/effect_sample2/node_modules/.pnpm/[email protected][email protected]/node_modules/drizzle-orm/sqlite-core/co
lumns/common", { with: { "resolution-mode": "import" } }).SQLiteColumn<any, object>' is not assignable to type 'import("D:/mfuku/Documents/projects/scratchProj/effect_sample2/node_modu
les/.pnpm/[email protected][email protected]/node_modules/drizzle-orm/sqlite-core/columns/common").SQLiteColumn<any, object>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
                  Property 'config' is protected but type 'Column<T, TRuntimeConfig, TTypeConfig>' is not a class derived from 'Column<T, TRuntimeConfig, TTypeConfig>'.

29   yield* db.insert(users).values({ id: 1, name: "Alice" })
                      ~~~~~

src/Program.ts:30:43 - error TS2345: Argument of type 'SQLiteTableWithColumns<{ name: "users"; schema: undefined; columns: { id: SQLiteColumn<{ name: "id"; tableName: "users"; dataType
: "number"; columnType: "SQLiteInteger"; data: number; driverParam: number; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, object>; name: SQLiteColumn<..
.>; ...' is not assignable to parameter of type 'SQLiteTable<TableConfig> | SQL<unknown> | Subquery<string, Record<string, unknown>> | SQLiteViewBase<string, boolean, ColumnsSelection>'.
  Type 'SQLiteTableWithColumns<{ name: "users"; schema: undefined; columns: { id: SQLiteColumn<{ name: "id"; tableName: "users"; dataType: "number"; columnType: "SQLiteInteger"; data: 
number; driverParam: number; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, object>; name: SQLiteColumn<...>; ...' is not assignable to type 'SQLiteTable<TableConfig>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
    The types of '_.config.columns' are incompatible between these types.
      Type '{ id: SQLiteColumn<{ name: "id"; tableName: "users"; dataType: "number"; columnType: "SQLiteInteger"; data: number; driverParam: number; notNull: true; hasDefault: true; enumValues: undefined; baseColumn: never; }, object>; name: SQLiteColumn<...>; }' is not assignable to type 'Record<string, SQLiteColumn<any, object>>'.
        Property 'id' is incompatible with index signature.
          Type 'SQLiteColumn<{ name: "id"; tableName: "users"; dataType: "number"; columnType: "SQLiteInteger"; data: number; driverParam: number; notNull: true; hasDefault: true; enum
Values: undefined; baseColumn: never; }, object>' is not assignable to type 'SQLiteColumn<any, object>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
            The types of 'table._.config.columns' are incompatible between these types.
              Type 'Record<string, import("D:/mfuku/Documents/projects/scratchProj/effect_sample2/node_modules/.pnpm/[email protected][email protected]/node_modules/drizzle-orm/s
qlite-core/columns/common", { with: { "resolution-mode": "import" } }).SQLiteColumn<any, object>>' is not assignable to type 'Record<string, import("D:/mfuku/Documents/projects/scratchProj/effect_sample2/node_modules/.pnpm/[email protected][email protected]/node_modules/drizzle-orm/sqlite-core/columns/common").SQLiteColumn<any, object>>'.
                'string' index signatures are incompatible.
                  Type 'import("D:/mfuku/Documents/projects/scratchProj/effect_sample2/node_modules/.pnpm/[email protected][email protected]/node_modules/drizzle-orm/sqlite-core/
columns/common", { with: { "resolution-mode": "import" } }).SQLiteColumn<any, object>' is not assignable to type 'import("D:/mfuku/Documents/projects/scratchProj/effect_sample2/node_mo
dules/.pnpm/[email protected][email protected]/node_modules/drizzle-orm/sqlite-core/columns/common").SQLiteColumn<any, object>' with 'exactOptionalPropertyTypes: true'. Consider adding 'undefined' to the types of the target's properties.
                    Property 'config' is protected but type 'Column<T, TRuntimeConfig, TTypeConfig>' is not a class derived from 'Column<T, TRuntimeConfig, TTypeConfig>'.

30   const results = yield* db.select().from(users)
                                             ~~~~~


Found 3 errors.

What is the expected behavior?

I found to build bellow setting

tsconfig.base.json

    "moduleResolution": "node",
    "module": "commonjs",

Is there a way to build without changing the settings? Is there any problem with this workaround?

What do you see instead?

No response

Additional information

No response

@mfukushim mfukushim added the bug Something isn't working label Dec 12, 2024
@EgorPopovPP
Copy link

Same problem :(

@mfukushim
Copy link
Author

Hello.
I don't know the cause of the problem either. Currently I am tentatively using the original drizzle wrapped with stubs instead of @effect/sql-drizzle. It is working fine for the time being, but I would like to know how to deal with it officially.

import {drizzle} from 'drizzle-orm/libsql';

    const stub = <T>(qy: Promise<T>) => Effect.tryPromise({
      try: () => qy,
      catch: error => {
        return new Error(`${error}`);
      }
    })

const db = drizzle(dbPath);

function getData(id:number) {
      return stub(db.select().from(data_schema).where(eq(data_schema.id, id))).pipe(Effect.tap(a => Effect.log(a)))
}

@EgorPopovPP
Copy link

EgorPopovPP commented Jan 3, 2025

@xesrevinu
Copy link

xesrevinu commented Jan 3, 2025

# env.d.ts
import type { PgRemoteQueryResultHKT } from "drizzle-orm/pg-proxy";

declare interface PgRemoteDatabase<
  TSchema extends Record<string, unknown> = Record<string, never>,
> extends PgDatabase<PgRemoteQueryResultHKT, TSchema> {}

declare module "drizzle-orm" {
  export interface QueryPromise<T> extends Effect.Effect<T, SqlError> {}
}

# sql.ts
const DB: Context.Tag<PgDrizzle.PgDrizzle, PgRemoteDatabase> =
  PgDrizzle.PgDrizzle as any;

There are indeed some strange problems here, which can be temporarily bypassed in this way.
@mfukushim Tested in EgorPopovPP/effect-issue-reproduction, contact me anytime if you have any findings.

image

@EgorPopovPP
Copy link

@xesrevinu Thank you! You are amazing!

@mfukushim
Copy link
Author

@xesrevinu
Thanks for the reply.
I tried pulling https://github.com/EgorPopovPP/effect-issue-reproduction in my environment and got the following error suggestions.
It's too complicated for me to fully understand, but hopefully something will help you.

image

@xesrevinu
Copy link

@xesrevinu

Thanks for the reply.

I tried pulling https://github.com/EgorPopovPP/effect-issue-reproduction in my environment and got the following error suggestions.

It's too complicated for me to fully understand, but hopefully something will help you.

image

#4125 (comment)

Have you tried to add this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants