我把实体保存在数据库中。
public async saveTask(toDoDto: CreateToDoDto) {
try {
const toDo: ToDo = this.todosRepository.create(toDoDto);
return await this.todosRepository
.createQueryBuilder()
.insert()
.into(ToDo)
.values(toDo)
.execute();
} catch (err) {
this.logger.error(err.message);
throw new WsException(err.message);
}
}
当我将实体保存到数据库时,我希望它返回给我。
如何获取数据库中刚刚保存的实体?
return await this.todosRepository
.createQueryBuilder()
.insert()
.into(ToDo)
.values(toDo)
.returning('*')
.execute();
我无法使用返回功能,因为我收到错误。
OUTPUT 或 RETURN 子句仅受 Microsoft SQL Server 或 PostgreSQL 数据库支持。
当我插入没有返回函数的数据库时,我得到以下响应。
InsertResult {
identifiers: Array(1),
generatedMaps: Array(1),
raw: OkPacket
}
在答案中,没有我写入数据库的实体。
如果返回函数不起作用,如何将记录的实体放入数据库他妈的 mysql?
(MySQLi Object-oriented (
$last_id = $conn->insert_id;
//$conn是与 SQL 建立的连接
(MySQLi procedural(
$last_id = mysqli_insert_id($conn);
(PDO(
$last_id = $conn->lastInsertId();