10000 Allow db.ref to insert arbitrary columns/tables to raw SQL · Issue #510 · romeerez/orchid-orm · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Allow db.ref to insert arbitrary columns/tables to raw SQL #510

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

Open
IlyaSemenov opened this issue May 16, 2025 · 0 comments
Open

Allow db.ref to insert arbitrary columns/tables to raw SQL #510

IlyaSemenov opened this issue May 16, 2025 · 0 comments

Comments

@IlyaSemenov
Copy link
Contributor

As a developer, I want to bulk migrate some tables within rake migrations, running a similar query for multiple tables. That's what I do:

  change(async (db, up) => {
    for (const t of ["foo", "bar", "baz"]) {
      if (up) {
        await db.query`update ${db.ref(t)} set tx_data = jsonb_build_object('id', tx_id) where tx_id is not null`
      } else {
        await db.query`update ${db.ref(t)} set tx_id = tx_data->>'id' where tx_data is not null`
      }
    }
  }),

Expected: db.ref(t) inserts table name to raw SQL.

Result:

[unhandledRejection] Cannot read properties of undefined (reading 'operators')

    at new RefExpression (node_modules/.pnpm/pqb@0.51.0/node_modules/pqb/src/queryMethods/expressions.ts:63:31)
    at Function.ref (node_modules/.pnpm/pqb@0.51.0/node_modules/pqb/src/queryMethods/expressions.ts:219:12)
    at Array.<anonymous> (server/db/migrations/0044_tx_data.ts:15:36)
  • orchid-orm 1.49.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0