diff --git a/examples/conn.ts b/examples/conn.ts index c3c4a0c..b2b0bdc 100644 --- a/examples/conn.ts +++ b/examples/conn.ts @@ -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(); diff --git a/src/client.ts b/src/client.ts index 213bfa6..6fa1026 100644 --- a/src/client.ts +++ b/src/client.ts @@ -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();