GithubHelp home page GithubHelp logo

coredatarepository's People

Contributors

roanutil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

coredatarepository's Issues

How to work with nested objects

Hello!

I saw your solution and it became interesting to understand how everything works. With primitive types there is no question, but with complex types it is not very clear. There are 2 questions:

  1. Let's say we have a ParentClass that has a relationship with one element of type ChildClass (1-to-1 relationship in CoreData model).
  2. Let's say we have a ParentClass that has an array of elements of the ChildClass type (1-to-many relationship in CoreData Model).

If it's not difficult for you, then I will be grateful to you for expanding the documentation with some simple example.

Thanks in advance for any answer!

More documentation around setting up a repo would be helpful

Hi Andrew,

First of all, thanks very much for the great work so far on this project!


However, being fairly new to Core Data I’m not sure exactly how you intend to set up and use this repo in a way that doesn’t block the main queue, whilst not hitting thread exceptions due to Core Data accessing objects on different threads.

So a few lines in the Readme or an example of a project where you set up Core data with TCA so that it can be used in the background would be great.

To give you a bit more idea of my particular use case:

I’m trying to move migrate a project (which uses TCA) over from Realm to Core Data and I’m struggling to get Core data to work (partly due to my lack of knowledge and partly due to the additional quirks of Core Data regarding thread safety), so I’m hoping your project can sidestep the issues I’m coming across.

Currently I have a non standard Realm set-up i.e. I am using it as a repository in a similar vein to this project, rather than with “live objects”. In this way I can offload requests to the background - I.e. I can say things like this in my reducers:

         environment.database
          .doRepoAction()
          .subscribe(on: environment.backgroundQueue)
          .receive(on: environment.mainQueue)
		…

So ideally I would like an example where you set up your core data repo in a way that frees up the main thread and can ideally be used in situations such as the above. All your tests seem to use the viewContext rather than a background context, so I would like to understand:

When you use this package, do you still need to use things like container.newBackgroundContext() and context.perform { }, and if so, can you please give a simple example of how you might do this?

Many thanks,
Adam

Error when trying to update entity

Hi,

I've been trying to use the library, but I'm confused with some behaviour around updating entities.

In particular I'm getting an error of the form "Attempt to access an object not found in store", when I try and update an entity.

Here is a minimal example of the strange behaviour, which you should be able to reproduce easily in the context of the CoreDataRepositoryTests:

  func testUpdateMovie() async throws {
    let container = CoreDataStack.persistentContainer
    let repositoryContext = container.viewContext
    repositoryContext.automaticallyMergesChangesFromParent = true
    let repo = CoreDataRepository(context: repositoryContext)
    
    let movie = Movie(id: UUID(), title: "Some Movie", releaseDate: Date())
    
    // We can create a movie
    let createRes = await repo.create(movie)
    let createdMovie = try! createRes.get()
    
    // We can then fetch the movie, e.g. by its title
    let fetchRequest = NSFetchRequest<RepoMovie>(entityName: "RepoMovie")
    fetchRequest.predicate = NSPredicate(format: "title == %@", movie.title)
    let fetchRes: Result<[Movie], CoreDataRepositoryError> = await repo.fetch(fetchRequest)
    let fetchedMovie = try fetchRes.get().first!
    print("Fetched Movie", fetchedMovie)
    
    // But if we try and update the movie we get a failure
    var updatedMovie = createdMovie
    updatedMovie.title = "Updated title"
    let updateRes = await repo.update(updatedMovie.managedRepoUrl!, with: updatedMovie)
    let _ = try! updateRes.get()
    
//    Fatal error: 'try!' expression unexpectedly raised an error: 
//    CoreDataRepository.CoreDataRepositoryError.coreData(Error Domain=NSCocoaErrorDomain Code=133000 
//    "Attempt to access an object not found in store."
  }

It is quite possible that I'm just using the library incorrectly, so any assistance with what I'm doing wrong would be most appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.