Skip to content

Commit

Permalink
feat(delete): 删除
Browse files Browse the repository at this point in the history
  • Loading branch information
jiawei397 committed Jun 19, 2021
1 parent bd1c2bf commit 078d637
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
16 changes: 15 additions & 1 deletion examples/conn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,25 @@ const update = async () => {
}
};

const deleteById = async () => {
try {
const info = await client.delete({
index: "myindex2",
id: 1,
});
console.log(info);
} catch (error) {
console.error(error);
}
};

console.time("ajax");
// await Array.from(new Array(100)).map(ajax);
// await create();
// await count();
await update();
// await update();

await deleteById();

// setTimeout(async () => {
// await create();
Expand Down
17 changes: 17 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@ export class Client {
});
}

delete(params: {
index: string;
id: string | number;
}) {
const {
id,
index,
} = params;
const path = "/" + encodeURIComponent(index) + "/" +
encodeURIComponent(type) +
"/" + encodeURIComponent(id);
return ajax({
url: path,
method: "DELETE",
});
}

close() {
if (this.conn) {
this.conn.close();
Expand Down

0 comments on commit 078d637

Please sign in to comment.