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
5 changes: 5 additions & 0 deletions .changeset/dry-bugs-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@powersync/common': minor
---

[Attachments] Added `AttachmentTableRecord` type, which describes the attachment table's row type.
17 changes: 16 additions & 1 deletion packages/common/etc/common.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,18 @@ export interface ArrayQueryDefinition<RowType = unknown> {
// @alpha
export const ATTACHMENT_TABLE = "attachments";

// @alpha (undocumented)
export const ATTACHMENT_TABLE_COLUMNS: {
filename: BaseColumnType<string | null>;
local_uri: BaseColumnType<string | null>;
timestamp: BaseColumnType<number | null>;
size: BaseColumnType<number | null>;
media_type: BaseColumnType<string | null>;
state: BaseColumnType<number | null>;
has_synced: BaseColumnType<number | null>;
meta_data: BaseColumnType<string | null>;
};

// @alpha
export class AttachmentContext {
constructor(db: AbstractPowerSyncDatabase, tableName: string | undefined, logger: ILogger, archivedCacheLimit: number);
Expand Down Expand Up @@ -506,14 +518,17 @@ export enum AttachmentState {
}

// @alpha
export class AttachmentTable extends Table {
export class AttachmentTable extends Table<typeof ATTACHMENT_TABLE_COLUMNS> {
constructor(options?: AttachmentTableOptions);
}

// @alpha (undocumented)
export interface AttachmentTableOptions extends Omit<TableV2Options, 'name' | 'columns'> {
}

// @alpha
export type AttachmentTableRecord = RowType<AttachmentTable>;

// @public (undocumented)
export type BaseColumnType<T extends number | string | null> = {
type: ColumnType;
Expand Down
49 changes: 29 additions & 20 deletions packages/common/src/attachments/Schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { column } from '../db/schema/Column.js';
import { Table } from '../db/schema/Table.js';
import { RowType, Table } from '../db/schema/Table.js';
import { TableV2Options } from '../db/schema/Table.js';

/**
Expand Down Expand Up @@ -66,30 +66,39 @@ export enum AttachmentState {
*/
export interface AttachmentTableOptions extends Omit<TableV2Options, 'name' | 'columns'> {}

/**
* @alpha
*/
export const ATTACHMENT_TABLE_COLUMNS = {
filename: column.text,
local_uri: column.text,
timestamp: column.integer,
size: column.integer,
media_type: column.text,
state: column.integer, // Corresponds to AttachmentState
has_synced: column.integer,
meta_data: column.text
};

/**
* AttachmentTable defines the schema for the attachment queue table.
*
* @alpha
*/
export class AttachmentTable extends Table {
export class AttachmentTable extends Table<typeof ATTACHMENT_TABLE_COLUMNS> {
constructor(options?: AttachmentTableOptions) {
super(
{
filename: column.text,
local_uri: column.text,
timestamp: column.integer,
size: column.integer,
media_type: column.text,
state: column.integer, // Corresponds to AttachmentState
has_synced: column.integer,
meta_data: column.text
},
{
...options,
viewName: options?.viewName ?? ATTACHMENT_TABLE,
localOnly: true,
insertOnly: false
}
);
super(ATTACHMENT_TABLE_COLUMNS, {
...options,
viewName: options?.viewName ?? ATTACHMENT_TABLE,
localOnly: true,
insertOnly: false
});
}
}

/**
* AttachmentTableRecord represents the row type of the attachment table.
*
* @alpha
*/
export type AttachmentTableRecord = RowType<AttachmentTable>;
Loading