ElectroDB類型安全的 DynamoDB 庫
ElectroDB 是一個(gè) DynamoDB 庫,以方便使用復(fù)雜的分層關(guān)系建模和實(shí)現(xiàn)單表設(shè)計(jì),同時(shí)保持你的查詢代碼可讀性。
特性:
- 與現(xiàn)有表一起使用- ElectroDB 簡化了 DocumentClient 參數(shù)的構(gòu)建,因此你可以將其與現(xiàn)有表/數(shù)據(jù)一起使用。
- 屬性架構(gòu)強(qiáng)制-為你的實(shí)體定義一個(gè)具有強(qiáng)制屬性驗(yàn)證、默認(rèn)值、類型、別名等的模式。
- 輕松編寫分層訪問模式- 為你的索引規(guī)劃和設(shè)計(jì)分層鍵,以增加你可能的訪問模式。
- 單表實(shí)體隔離- 使用 ElectroDB 創(chuàng)建的實(shí)體在使用單表時(shí)不會(huì)與其他實(shí)體發(fā)生沖突。
- 簡化的排序鍵條件查詢- 通過輕松構(gòu)建組合鍵來編寫高效的排序鍵查詢。
- 簡化的 Filter Composition-輕松創(chuàng)建 DynamoDB 查詢復(fù)雜可讀的過濾器,而無需擔(dān)心
ExpressionAttributeNames、ExpressionAttributeValues以及FilterExpressions的實(shí)現(xiàn)。 - 簡化的 Update Expression Composition-輕松制作類型安全的更新操作,而無需格式化繁瑣的
ExpressionAttributeNames、ExpressionAttributeValues和UpdateExpressions。 - 跨實(shí)體輕松查詢- 定義“集合”以創(chuàng)建強(qiáng)大/慣用的查詢,這些查詢在單個(gè)請求中返回多個(gè)實(shí)體。
- 自動(dòng)索引選擇- 使用
.find()或.match()方法根據(jù)定義的排序鍵結(jié)構(gòu)動(dòng)態(tài)有效地查詢。 - 簡化的分頁 API -
.page()用于輕松地對結(jié)果集進(jìn)行分頁。 - 與你現(xiàn)有的解決方案一起使用- 如果你已經(jīng)在使用 DynamoDB,并且想要使用 ElectroDB,請使用自定義復(fù)合屬性模板來利用您現(xiàn)有的密鑰結(jié)構(gòu)。
- TypeScript 支持-現(xiàn)在在 Beta 版中為實(shí)體和服務(wù)提供強(qiáng)大的TypeScript支持。
- 通過查詢終端直接-直接從命令行對你的實(shí)體、服務(wù)、模型執(zhí)行查詢。
- Stand Up Rest Server for Entity - 建立一個(gè) REST Server 來與你的實(shí)體、服務(wù)、模型進(jìn)行交互,以便更容易進(jìn)行原型設(shè)計(jì)。
Turn this
tasks .patch({ team: "core", task: "45-662", project: "backend" }) .set({ status: "open" }) .add({ points: 5 }) .append({ comments: [{ user: "janet", body: "This seems half-baked." }] }) .where(( {status}, {eq} ) => eq(status, "in-progress")) .go();
Into This
{
"UpdateExpression": "SET #status = :status_u0, #points = #points + :points_u0, #comments = list_append(#comments, :comments_u0), #updatedAt = :updatedAt_u0, #gsi1sk = :gsi1sk_u0",
"ExpressionAttributeNames": {
"#status": "status",
"#points": "points",
"#comments": "comments",
"#updatedAt": "updatedAt",
"#gsi1sk": "gsi1sk"
},
"ExpressionAttributeValues": {
":status0": "in-progress",
":status_u0": "open",
":points_u0": 5,
":comments_u0": [
{
"user": "janet",
"body": "This seems half-baked."
}
],
":updatedAt_u0": 1630977029015,
":gsi1sk_u0": "$assignments#tasks_1#status_open"
},
"TableName": "your_table_name",
"Key": {
"pk": "$taskapp#team_core",
"sk": "$tasks_1#project_backend#task_45-662"
},
"ConditionExpression": "attribute_exists(pk) AND attribute_exists(sk) AND #status = :status0"
}
評論
圖片
表情
