dflourusso / expo-sqlite-orm

Expo SQLite ORM
132 stars 34 forks source link

Proposal: use hook to listen for table changes. #69

Open eznix86 opened 5 months ago

eznix86 commented 5 months ago

Example

const users = useSQLite(['users']) // is connected to insert, update, delete option. but is only connected with the mentioned table. 
// if 'animal' is not specified for example, it will not trigger changes

users.map((user) => {

 user.delete() // trigger update
})

db.delete(user) // trigger update
angelxmoreno commented 2 months ago

I have explored this idea. It would be interesting to know if this feature fits within the goals for the project. thoughts @dflourusso ?

Essentially the feature translates into making the orm reactive. There are several layers of complexity that would require much discussion.

eznix86 commented 2 months ago

I think it can be summarize like.

The library does a select and load it into state.

But instead of write arrays of data it loads an instance of the orm into memory.

It can extend useState or useContext but either way. It would be a nice addition.

angelxmoreno commented 2 months ago

right, but keep in mind that the "state" would be local to that one component. in a situation where you have multiple components loaded, tat "state" would not be shared with siblings. That could be an acceptable but not in al situations.

eznix86 commented 2 months ago

Agree 100 percent, what if it acts like a store, so the useSQLite is not just for one component but it is a store ?

angelxmoreno commented 2 months ago

and there is where things become slightly more complex than just tracking a single state. Don't get me wrong, doable, but I feel like creating a wrapper for expo-sqlite-orm in another repo would be better.

@eznix86 you have time to contribute to this?

eznix86 commented 2 months ago

I can try in my spare time. Do you mean in this repository or another project on top of this one ?

angelxmoreno commented 2 months ago

I hit you up on X but not sure if that's the best way to communicate. What I'm thinking is another project that has expo-sqlite-orm as a peer-deps. It would be easier for @dflourusso to port the code once we battle test this feature