Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/schema/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe("Project Schema", () => {
expect((project.tinybird as unknown as Record<string, unknown>).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() },
});
Expand All @@ -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");
Expand Down Expand Up @@ -316,7 +317,7 @@ describe("Project Schema", () => {
expect((client as unknown as Record<string, unknown>).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() },
});
Expand All @@ -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");
Expand Down
7 changes: 7 additions & 0 deletions src/schema/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
DatasourcesNamespace,
DeleteOptions,
DeleteResult,
IngestOptions,
IngestResult,
QueryOptions,
QueryResult,
Expand Down Expand Up @@ -69,6 +70,8 @@ type PipeEntityAccessors<T extends PipesDefinition> = {
type DatasourceAccessor<T extends DatasourceDefinition<SchemaDefinition>> = {
/** Ingest a single event row */
ingest(event: InferRow<T>): Promise<IngestResult>;
/** Ingest multiple event rows in a batch */
ingestBatch(events: InferRow<T>[], options?: IngestOptions): Promise<IngestResult>;
/** Append data from a URL or file */
append(options: AppendOptions): Promise<AppendResult>;
/** Replace datasource content from a URL or file */
Expand Down Expand Up @@ -358,6 +361,10 @@ export const Tinybird: TinybirdConstructor = class Tinybird<
const client = await this.#getClient();
return client.datasources.ingest(tinybirdName, event as Record<string, unknown>);
},
ingestBatch: async (events: unknown[], options: IngestOptions = {}) => {
const client = await this.#getClient();
return client.ingestBatch(tinybirdName, events as Record<string, unknown>[], options);
},
append: async (options: AppendOptions) => {
const client = await this.#getClient();
return client.datasources.append(tinybirdName, options);
Expand Down
Loading