RETURNING Clause Issue with Kysely Oracle Adapter #2116

Closed
opened 2026-03-13 09:28:30 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @Thomas-Matheus on GitHub (Oct 13, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Oracle Database Support - RETURNING Clause Issue with Kysely Adapter

Summary

When using Better Auth with the Kysely adapter (kysely with kysely-oracledb and oracledb) and Oracle Database, user creation fails because Oracle doesn't support the standard RETURNING * clause used in INSERT statements.

Current Implementation

I'm using the Kysely adapter with Oracle Database in my Better Auth setup:

import { Kysely } from 'kysely';
import { OracleDialect } from 'kysely-oracledb';
import { betterAuth } from 'better-auth';

let dbInstance: Kysely<any> | null = null;

async function getDb(): Promise<Kysely<any>> {
  if (!dbInstance) {
    const pool = await initializePool();
    dbInstance = new Kysely({
      dialect: new OracleDialect({
        pool,
      }),
      log: console.log,
    });
  }
  return dbInstance;
}

export async function createAuth() {
  const db = await getDb();

  return betterAuth({
    database: kyselyAdapter(db, {
      provider: 'oracle',
    }),
    emailAndPassword: {
      enabled: true,
    },
    plugins: [
      openAPI(),
      // ... other plugins
    ],
    // ... other config
  });
}

After try to create a user POST: api/auth/sign-up/email I have the error regarding RETURNING clause

Is it possible omit the RETURNING clause and perform a separate SELECT query (like it does for MySQL),

Current vs. Expected behavior

When I tried to create a user I got the error because of the RETURNING clause that is used in the insert that looks like in Oracle not support it on INSERT.

I noticed in the code base in this line kysely-adapter.ts#L65 that have a validation that make another search to return the data for mysql.

if (dialect === 'mysql') {
  // Special handling for MySQL
}

Is it possible include the oracle on that as well?

What version of Better Auth are you using?

1.3.27

System info

{
  "system": {
    "platform": "win32",
    "arch": "x64",
    "version": "Windows 11 Pro",
    "release": "10.0.26100",
    "cpuCount": 12,
    "cpuModel": "AMD Ryzen 5 5600X 6-Core Processor",
    "totalMemory": "15.93 GB",
    "freeMemory": "2.15 GB"
  },
  "node": {
    "version": "v22.17.1",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "10.9.2"
  },
  "frameworks": null,
  "databases": null,
  "betterAuth": {
    "version": "latest",
    "config": null
  }
}

Which area(s) are affected? (Select all that apply)

Backend

Auth config (if applicable)


Additional context

No response

Originally created by @Thomas-Matheus on GitHub (Oct 13, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce ## Oracle Database Support - RETURNING Clause Issue with Kysely Adapter ### Summary When using Better Auth with the Kysely adapter (`kysely` with `kysely-oracledb` and `oracledb`) and Oracle Database, user creation fails because Oracle doesn't support the standard `RETURNING *` clause used in INSERT statements. ### Current Implementation I'm using the Kysely adapter with Oracle Database in my Better Auth setup: ```typescript import { Kysely } from 'kysely'; import { OracleDialect } from 'kysely-oracledb'; import { betterAuth } from 'better-auth'; let dbInstance: Kysely<any> | null = null; async function getDb(): Promise<Kysely<any>> { if (!dbInstance) { const pool = await initializePool(); dbInstance = new Kysely({ dialect: new OracleDialect({ pool, }), log: console.log, }); } return dbInstance; } export async function createAuth() { const db = await getDb(); return betterAuth({ database: kyselyAdapter(db, { provider: 'oracle', }), emailAndPassword: { enabled: true, }, plugins: [ openAPI(), // ... other plugins ], // ... other config }); } ``` After try to create a user `POST: api/auth/sign-up/email` I have the error regarding `RETURNING` clause Is it possible omit the `RETURNING` clause and perform a separate `SELECT` query (like it does for MySQL), ### Current vs. Expected behavior When I tried to create a user I got the error because of the `RETURNING clause` that is used in the `insert` that looks like in **Oracle** not support it on `INSERT`. I noticed in the code base in this line [kysely-adapter.ts#L65](https://github.com/better-auth/better-auth/blob/canary/packages/better-auth/src/adapters/kysely-adapter/kysely-adapter.ts#L65) that have a validation that make another search to return the data for `mysql`. ```typescript if (dialect === 'mysql') { // Special handling for MySQL } ``` Is it possible include the `oracle` on that as well? ### What version of Better Auth are you using? 1.3.27 ### System info ```bash { "system": { "platform": "win32", "arch": "x64", "version": "Windows 11 Pro", "release": "10.0.26100", "cpuCount": 12, "cpuModel": "AMD Ryzen 5 5600X 6-Core Processor", "totalMemory": "15.93 GB", "freeMemory": "2.15 GB" }, "node": { "version": "v22.17.1", "env": "development" }, "packageManager": { "name": "npm", "version": "10.9.2" }, "frameworks": null, "databases": null, "betterAuth": { "version": "latest", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript ``` ### Additional context _No response_
GiteaMirror added the adapter label 2026-03-13 09:28:30 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Oct 13, 2025):

Hi @Thomas-Matheus! I'm Dosu and I’m helping the better-auth team.

The Better Auth Kysely adapter does not currently handle Oracle's lack of support for the RETURNING clause. The adapter has special logic for MySQL that omits RETURNING and performs a separate SELECT to fetch the inserted row, but Oracle is not included in this logic, so it falls back to using returningAll(), which causes errors with OracleDB see source.

You can work around this by modifying the adapter to treat Oracle the same way as MySQL: in the withReturning function, update the conditional to check for both mysql and oracle (e.g., if (config?.type === "mysql" || config?.type === "oracle")), then omit the RETURNING clause and perform a separate SELECT to retrieve the inserted row. This approach matches the current workaround for MySQL and should resolve the issue for Oracle.

There is no official support or merged PR for this yet, so manual changes are required until the adapter is updated upstream.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Oct 13, 2025): <!-- Greeting --> Hi @Thomas-Matheus! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> The Better Auth Kysely adapter does not currently handle Oracle's lack of support for the `RETURNING` clause. The adapter has special logic for MySQL that omits `RETURNING` and performs a separate `SELECT` to fetch the inserted row, but Oracle is not included in this logic, so it falls back to using `returningAll()`, which causes errors with OracleDB [see source](https://github.com/better-auth/better-auth/blob/c3acb35269bb2881d30580a6bfc5a0dd4ccb8691/packages/better-auth/src/adapters/kysely-adapter/kysely-adapter.ts). You can work around this by modifying the adapter to treat Oracle the same way as MySQL: in the `withReturning` function, update the conditional to check for both `mysql` and `oracle` (e.g., `if (config?.type === "mysql" || config?.type === "oracle")`), then omit the `RETURNING` clause and perform a separate `SELECT` to retrieve the inserted row. This approach matches the current workaround for MySQL and should resolve the issue for Oracle. There is no official support or merged PR for this yet, so manual changes are required until the adapter is updated upstream. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/c2f1d4b2-03bb-4cf7-a12d-44744da80686?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/c2f1d4b2-03bb-4cf7-a12d-44744da80686?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/c2f1d4b2-03bb-4cf7-a12d-44744da80686?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/c2f1d4b2-03bb-4cf7-a12d-44744da80686?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/c2f1d4b2-03bb-4cf7-a12d-44744da80686?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/c2f1d4b2-03bb-4cf7-a12d-44744da80686?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/c2f1d4b2-03bb-4cf7-a12d-44744da80686?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/5282)
Author
Owner

@Bekacru commented on GitHub (Oct 16, 2025):

you should pass mysql instead in the provider option. We don't support oracle as an option

@Bekacru commented on GitHub (Oct 16, 2025): you should pass `mysql` instead in the provider option. We don't support `oracle` as an option
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2116