Skip to content

Reactive functionality #1176

Open
Open
@imseonho

Description

@imseonho

Hello!

I made my application with SQLite, SwiftUI, Combine, MVVM, etc.

Issue

And I needed some feature to refresh view when the database table changes in my app.

I implemented like,

  • user clicks a button
  • then, app inserts some data to DB
  • to do refresh work, app selects from DB

And I encountered an error, saying "database is locked (code: 5)", like below.

스크린샷 2022-11-17 오후 7 00 13

The app crashed when I try select action right after insert action.

And I searched about this error, and I got some clue at this. -> Link

The problem was "conflict between two transactions running on the same database connection".

So, to fix this problem, I want to make the select work is done definitely after insert work.

Therefore, some reactive functionality can be helpful, so that only when the database table changes, app does select action again to refresh view.

Is there any technique to help reactive view refresh in point of SQLite local DB?

I found some possible method,

  • using NotificationCenter and updateHook() method

But, I have no idea how to actually implement like this. I need more detailed explain...

Build Information

I added SQLite version 0.13.2 with CocoaPods.

'SQLite.swift', '~> 0.13.2'

And I use Xcode version 14.1, macOS Monterey version 12.6.

Related Issue

I checked issue #686,
and I hope to know more information about that.

Any clues will be helpful.

With Love 🫶,
Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions