假设我有一个像这样的简单 TypeORM 实体:
import { Entity, PrimaryGeneratorColumn, Column } from 'typeorm';
@Entity()
export class Employee {
@PrimaryGeneratedColumn()
id: number;
@Column()
Name: string;
}
Run Code Online (Sandbox Code Playgroud)
只要我不手动接触数据库,一切都可以正常工作。如果我手动输入记录,实体将无法检查id表中的最后一个当前记录并抛出 error duplicate key value violates unique constraint。
例如:
Employee Entity自己创建两条记录。id 2id 3Employee Entity运行时,它不会 = 创建另一个记录,因为它想使用id 3,但我已经手动添加了。duplicate key value violates unique constraintEmployee Entity再次运行时,它会起作用,因为它尝试在已经可用的情况下保存另一条记录id 4。那么我如何确保检查Employee Entity数据库中的最后一个 id,然后使用增量保存下一条记录id?
谢谢
我在 React 应用程序中看到了以下代码。
getData()
.then(res => res.json())
.then(console.log)
Run Code Online (Sandbox Code Playgroud)
它的行为与我使用的完全相同
getAllStudents()
.then(res => res.json())
.then(data => console.log(data))
Run Code Online (Sandbox Code Playgroud)
因此,在第一个示例中,被调用的函数console.log以某种方式隐式知道它应该将数据作为参数并将其显示在控制台中。该函数甚至没有被调用console.log()
你能告诉我这个快捷方式概念叫什么吗?我想了解更多有关它的信息,但我不知道应该如何使用它。
我在一篇教程中看到了这段代码片段:
\nconst myFunction = () => {\n return function (caller) {\n caller(firstFuctnion());\n caller(secondFunction());\n };\n};\nRun Code Online (Sandbox Code Playgroud)\n一旦我这样称呼它,你能告诉我它是如何工作的吗:
\nmyFunction()\nRun Code Online (Sandbox Code Playgroud)\ncaller当参数实际上未定义时,为什么我没有 \xe2\x80\x99t 收到错误?
另一方面,如果我省略它并编写如下代码:
\nconst myFunction = () => {\n return function () {\n firstFuctnion();\n secondFunction();\n };\n };\nRun Code Online (Sandbox Code Playgroud)\n这两个函数firstFuction()和secondFunction()\xe2\x80\x99t 被执行。那么,caller\xe2\x80\x8a\xe2\x80\x94\xe2\x80\x8a 到底是如何调用\xe2\x80\x80\x99\xe2\x80\x8a\xe2\x80\x94\xe2\x80\ x8a 工作吗?
对于那些可能想查看完整功能代码的人:
\nconst myFunction = () => {\n return function (caller) {\n caller(firstFuctnion());\n caller(secondFunction());\n };\n};\nRun Code Online (Sandbox Code Playgroud)\r\n我不明白这部分。那dispatch实际上是做什么的。它没有作为参数传递,也没有在任何地方定义它是什么。是功能吗?我可以whatever在那里写。 …