Skip to content

feat: improve powersync_core attachments API #343

@itsezlife

Description

@itsezlife
  1. The updateHook is required for saveFile and deleteFile in AttachmentQueue. Why is it required? In my personal use-case, I’ve never used updateHook.
  2. The updateHook can confuse people. When I tried to use updateHook in saveFile I needed to UPDATE ${AttachmentsQueueTable.defaultTableName} SET message_id = ? WHERE id = , and it didn’t work, because updateHook is called before it inserted into attachments queue table, therefore I couldn’t execute update statement. It can be solved by introducing preUpdateHook and postUpdateHook, or something like that. Or we could have a single updateHook, but call it after the *await* attachmentContext.upsertAttachment(attachment, tx);, in the saveFile specifically.
  3. When calling deleteFile , first it checks if attachment exists in the queue. If it doesn’t, attachment not found exception is thrown. It makes sense, but in my specific use-case I can call deleteFile mostly to delete attachment from the remote storage, sometimes it may not be inside the attachments queue, therefore it won’t be deleted. I have to call both deleteFile from AttachmentsQueue and RemoteStorage(which deletes from Supabase storage) in order to ensure that even when sometimes attachment may not exist in the queue, the attachment is 100% deleted from the storage. I’m just sharing about my experience and not sure whether anything needs to be touched here.
/// Resolves the filename for new attachment items.
  /// Concatenates the attachment ID and extension by default.
  Future<String> resolveNewAttachmentFilename(
    String attachmentId,
    String? fileExtension,
  ) async {
    return '$attachmentId.${fileExtension ?? 'dat'}';
  }

Why you always append extension in the resolveNewAttachmentFilename? Why just not append any extension if user has specifically not passed any extension(when fileExtension is null). I found it really frustrating. In old powersync_attachments_helper I could override those methods, but now AttachmentQueue is not extendable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions