diff --git a/src/schema/project.test.ts b/src/schema/project.test.ts index dc17874..f8deba6 100644 --- a/src/schema/project.test.ts +++ b/src/schema/project.test.ts @@ -94,7 +94,7 @@ describe("Project Schema", () => { expect((project.tinybird as unknown as Record).pipes).toBeUndefined(); }); - it("creates datasource accessors with ingest/append/replace/delete/truncate methods", () => { + it("creates datasource accessors with ingest/ingestBatch/append/replace/delete/truncate methods", () => { const events = defineDatasource("events", { schema: { timestamp: t.dateTime() }, }); @@ -105,6 +105,7 @@ describe("Project Schema", () => { expect(project.tinybird.events).toBeDefined(); expect(typeof project.tinybird.events.ingest).toBe("function"); + expect(typeof project.tinybird.events.ingestBatch).toBe("function"); expect(typeof project.tinybird.events.append).toBe("function"); expect(typeof project.tinybird.events.replace).toBe("function"); expect(typeof project.tinybird.events.delete).toBe("function"); @@ -316,7 +317,7 @@ describe("Project Schema", () => { expect((client as unknown as Record).pipes).toBeUndefined(); }); - it("creates datasource accessors with ingest/append/replace/delete/truncate methods", () => { + it("creates datasource accessors with ingest/ingestBatch/append/replace/delete/truncate methods", () => { const events = defineDatasource("events", { schema: { id: t.string() }, }); @@ -328,6 +329,7 @@ describe("Project Schema", () => { expect(client.events).toBeDefined(); expect(typeof client.events.ingest).toBe("function"); + expect(typeof client.events.ingestBatch).toBe("function"); expect(typeof client.events.append).toBe("function"); expect(typeof client.events.replace).toBe("function"); expect(typeof client.events.delete).toBe("function"); diff --git a/src/schema/project.ts b/src/schema/project.ts index 540d547..994ff33 100644 --- a/src/schema/project.ts +++ b/src/schema/project.ts @@ -14,6 +14,7 @@ import type { DatasourcesNamespace, DeleteOptions, DeleteResult, + IngestOptions, IngestResult, QueryOptions, QueryResult, @@ -69,6 +70,8 @@ type PipeEntityAccessors = { type DatasourceAccessor> = { /** Ingest a single event row */ ingest(event: InferRow): Promise; + /** Ingest multiple event rows in a batch */ + ingestBatch(events: InferRow[], options?: IngestOptions): Promise; /** Append data from a URL or file */ append(options: AppendOptions): Promise; /** Replace datasource content from a URL or file */ @@ -358,6 +361,10 @@ export const Tinybird: TinybirdConstructor = class Tinybird< const client = await this.#getClient(); return client.datasources.ingest(tinybirdName, event as Record); }, + ingestBatch: async (events: unknown[], options: IngestOptions = {}) => { + const client = await this.#getClient(); + return client.ingestBatch(tinybirdName, events as Record[], options); + }, append: async (options: AppendOptions) => { const client = await this.#getClient(); return client.datasources.append(tinybirdName, options);