Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read only store in app bundle #491

Open
missphyrgames opened this issue Nov 11, 2023 · 3 comments
Open

Read only store in app bundle #491

missphyrgames opened this issue Nov 11, 2023 · 3 comments

Comments

@missphyrgames
Copy link

Hey! I'm trying to create a sample app with the library and the aim is to have a read only store that's supplied with the app bundle and a read-write store in their documents (or the default location where this library/core data creates them). For example, suppose it's a Contacts app where there's a contact entity and also a favourites entity. The user would be supplied with default contacts that they can only read from. They can favourite these contacts which would be visible in another page.

A way to do this with core data was by using fetched properties, however, you can't create relationships between the stores unfortunately so it didn't work well for my situation (as I also wanted to sort the favourites based on the name of the contact). The reason I wanted to have a read only store was so I could easily update the data in an app update without re-seeding core data.

Is there a way I could accomplish it with this library? Or do you have any suggestions on how to implement this? Thank you :)

@JohnEstropia
Copy link
Owner

I think you have two requirements here so I'll split my comments for each:

1. Need for read-only store

You can actually create the SQLite file separately and bundle that into your app. The good thing is that you can use the exact models you use on iOS (etc.) and generate the SQLite files from a macOS playground or command line app for example.

You'd then have to copy that file into the app sandbox on the first launch (or overwrite as needed). CoreStore currently has no "readonly" mechanism at the store level, so you'd have to do this file management yourself.

2. Need for cross-store relationships

CoreStore also has no specific API for this, but you can easily declare multiple DataStacks and manually fetch the static data from one of them using a shared foreign key.

@missphyrgames
Copy link
Author

Thank you for your reply!

For the first point, I actually did try that out and it worked but I had to use fetched properties if I wanted anything similar to a relationship (but this had it's downfalls and limitations). Unless by copying it over we can setup relationships? I'm still slightly confused on this point. How would we setup relationships?

For the second point, I couldn't find any examples of manually fetching the data using a shared foreign key. What do you mean by this?

Sorry, I'm still relatively new to iOS development but really appreciate the help!

@JohnEstropia
Copy link
Owner

Sorry for the radio silence. By foreign key, it means some sort of ID that identifies a related object. So you store it as a field and then later use the ID to fetch the actual object. Basically similar to fetched properties.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants