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,
]
]
*/
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server