© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago
wermington

Mapping/Renaming column names for MariaDB when using RETURNING *

I know that RETURNING is not supported for MySQL but MariaDB supports it, so I have tried to "hack" it somehow using custom raw query.
I would like to ask:
1) Is it possible to use internal mapper for column names from the schema definition, in order to avoid manually "renaming" them?
2) Is there a better way to write this?
My code looks like this:
const insertQuery = this.ctDb
            .insert(someTable)
            .values(opts)
            .getSQL();
insertQuery.append(sql` RETURNING *`);
const execResult = await this.ctDb.execute(insertQuery);
const resultList = execResult[0] as any;
const result = resultList[0] as any;
// For creating this entity I would like to use the mapper
const entity = {
    id: result.id,
    systemName: result.system_name,
};

/*
Exec result looks like this:
[
  [
    {
      id: 96,
      system_name: 'test-24533',
    }
  ],
  [
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `system_name` VARCHAR(20) NOT NULL UNIQUE_KEY,
  ]
]
*/
const insertQuery = this.ctDb
            .insert(someTable)
            .values(opts)
            .getSQL();
insertQuery.append(sql` RETURNING *`);
const execResult = await this.ctDb.execute(insertQuery);
const resultList = execResult[0] as any;
const result = resultList[0] as any;
// For creating this entity I would like to use the mapper
const entity = {
    id: result.id,
    systemName: result.system_name,
};

/*
Exec result looks like this:
[
  [
    {
      id: 96,
      system_name: 'test-24533',
    }
  ],
  [
    `id` INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
    `system_name` VARCHAR(20) NOT NULL UNIQUE_KEY,
  ]
]
*/
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Issue with truncating column names using `with`
Drizzle TeamDTDrizzle Team / help
2y ago
SQL syntax error when using relations in MariaDB
Drizzle TeamDTDrizzle Team / help
3y ago
$returningId returning extra rows
Drizzle TeamDTDrizzle Team / help
17mo ago
Dynamic function get use typed column names using getTableConfig
Drizzle TeamDTDrizzle Team / help
2y ago