您可以使用 dynamoose 让多个模型共享一个表吗?这是我希望将它们保存在同一个表中的两个模型,并通过它们的type
哈希键和id
范围键来区分它们。
const Courses = dynamoose.model(
process.env.CONTENT_TABLE,
new dynamoose.Schema(
{
id: { type: String, rangeKey: true },
type: { type: String, hashKey: true },
department: { type: String },
description: { type: String },
image: { type: String },
name: { type: String },
},
{
throughput: 1,
timestamps: true
}
),
{ update: true }
);
const Teachers = dynamoose.model(
process.env.CONTENT_TABLE,
new dynamoose.Schema(
{
id: { type: String, rangeKey: true },
type: { type: String, hashKey: true },
picture: { type: String },
name: { type: String },
bio: { type: String }
},
{
throughput: 1,
timestamps: true
}
),
{ update: true }
);
这些是我使用的方法。我可以在 console.logging 中告诉 args 参数有我期望进入new ...
. new Course
or函数的 return 语句new Teachers
包含我添加的所有参数,但它们实际上并没有在数据库中结束。这是为什么?
create: ({ args, context }) =>
new Courses({
id: shortid.generate(),
type: course,
...args
}).save()
create: ({ args, context }) => {
console.log(args);
return new Teachers({
id: shortid.generate(),
type: teacher,
...args
}).save();