1- import { Column , ColumnType , Table } from "@journeyapps/powersync-sdk-common" ;
1+ import {
2+ Column ,
3+ ColumnType ,
4+ Table ,
5+ TableOptions ,
6+ } from "@journeyapps/powersync-sdk-common" ;
27
38export const ATTACHMENT_TABLE = "attachments" ;
49
@@ -20,16 +25,25 @@ export enum AttachmentState {
2025 ARCHIVED = 4 , // Attachment has been orphaned, i.e. the associated record has been deleted
2126}
2227
23- export function createAttachmentTable ( name : string = ATTACHMENT_TABLE ) {
24- return Table . createLocalOnly ( {
25- name : name ,
26- columns : [
27- new Column ( { name : "filename" , type : ColumnType . TEXT } ) ,
28- new Column ( { name : "local_uri" , type : ColumnType . TEXT } ) ,
29- new Column ( { name : "timestamp" , type : ColumnType . INTEGER } ) ,
30- new Column ( { name : "size" , type : ColumnType . INTEGER } ) ,
31- new Column ( { name : "media_type" , type : ColumnType . TEXT } ) ,
32- new Column ( { name : "state" , type : ColumnType . INTEGER } ) , // Corresponds to AttachmentState
33- ] ,
34- } ) ;
28+ export interface AttachmentTableOptions extends Omit < TableOptions , "name" > {
29+ name ?: string ;
30+ additionalColumns ?: Column [ ] ;
31+ }
32+
33+ export class AttachmentTable extends Table {
34+ constructor ( options : AttachmentTableOptions ) {
35+ super ( {
36+ ...options ,
37+ name : options . name ?? ATTACHMENT_TABLE ,
38+ columns : [
39+ new Column ( { name : "filename" , type : ColumnType . TEXT } ) ,
40+ new Column ( { name : "local_uri" , type : ColumnType . TEXT } ) ,
41+ new Column ( { name : "timestamp" , type : ColumnType . INTEGER } ) ,
42+ new Column ( { name : "size" , type : ColumnType . INTEGER } ) ,
43+ new Column ( { name : "media_type" , type : ColumnType . TEXT } ) ,
44+ new Column ( { name : "state" , type : ColumnType . INTEGER } ) , // Corresponds to AttachmentState
45+ ...( options . additionalColumns ?? [ ] ) ,
46+ ] ,
47+ } ) ;
48+ }
3549}
0 commit comments