Skip to content

Commit dea53a2

Browse files
authored
Merge pull request #138 from tinybirdco/fix/132-ingest-batch-accessor
feat: add ingestBatch method to datasource accessors
2 parents e04892c + 844ae2c commit dea53a2

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/schema/project.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ describe("Project Schema", () => {
9494
expect((project.tinybird as unknown as Record<string, unknown>).pipes).toBeUndefined();
9595
});
9696

97-
it("creates datasource accessors with ingest/append/replace/delete/truncate methods", () => {
97+
it("creates datasource accessors with ingest/ingestBatch/append/replace/delete/truncate methods", () => {
9898
const events = defineDatasource("events", {
9999
schema: { timestamp: t.dateTime() },
100100
});
@@ -105,6 +105,7 @@ describe("Project Schema", () => {
105105

106106
expect(project.tinybird.events).toBeDefined();
107107
expect(typeof project.tinybird.events.ingest).toBe("function");
108+
expect(typeof project.tinybird.events.ingestBatch).toBe("function");
108109
expect(typeof project.tinybird.events.append).toBe("function");
109110
expect(typeof project.tinybird.events.replace).toBe("function");
110111
expect(typeof project.tinybird.events.delete).toBe("function");
@@ -316,7 +317,7 @@ describe("Project Schema", () => {
316317
expect((client as unknown as Record<string, unknown>).pipes).toBeUndefined();
317318
});
318319

319-
it("creates datasource accessors with ingest/append/replace/delete/truncate methods", () => {
320+
it("creates datasource accessors with ingest/ingestBatch/append/replace/delete/truncate methods", () => {
320321
const events = defineDatasource("events", {
321322
schema: { id: t.string() },
322323
});
@@ -328,6 +329,7 @@ describe("Project Schema", () => {
328329

329330
expect(client.events).toBeDefined();
330331
expect(typeof client.events.ingest).toBe("function");
332+
expect(typeof client.events.ingestBatch).toBe("function");
331333
expect(typeof client.events.append).toBe("function");
332334
expect(typeof client.events.replace).toBe("function");
333335
expect(typeof client.events.delete).toBe("function");

src/schema/project.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
DatasourcesNamespace,
1515
DeleteOptions,
1616
DeleteResult,
17+
IngestOptions,
1718
IngestResult,
1819
QueryOptions,
1920
QueryResult,
@@ -69,6 +70,8 @@ type PipeEntityAccessors<T extends PipesDefinition> = {
6970
type DatasourceAccessor<T extends DatasourceDefinition<SchemaDefinition>> = {
7071
/** Ingest a single event row */
7172
ingest(event: InferRow<T>): Promise<IngestResult>;
73+
/** Ingest multiple event rows in a batch */
74+
ingestBatch(events: InferRow<T>[], options?: IngestOptions): Promise<IngestResult>;
7275
/** Append data from a URL or file */
7376
append(options: AppendOptions): Promise<AppendResult>;
7477
/** Replace datasource content from a URL or file */
@@ -358,6 +361,10 @@ export const Tinybird: TinybirdConstructor = class Tinybird<
358361
const client = await this.#getClient();
359362
return client.datasources.ingest(tinybirdName, event as Record<string, unknown>);
360363
},
364+
ingestBatch: async (events: unknown[], options: IngestOptions = {}) => {
365+
const client = await this.#getClient();
366+
return client.ingestBatch(tinybirdName, events as Record<string, unknown>[], options);
367+
},
361368
append: async (options: AppendOptions) => {
362369
const client = await this.#getClient();
363370
return client.datasources.append(tinybirdName, options);

0 commit comments

Comments
 (0)