GithubHelp home page GithubHelp logo

Comments (5)

pnewell avatar pnewell commented on June 26, 2024

Same thing happens even when using defaultStore(). If I rebuild and try and run a second time and write to the store, on write attempt I get the error "Is a directory"

from codabledatastore.

pnewell avatar pnewell commented on June 26, 2024

I believe this line is the source of the issue:

            let data = try Data(contentsOf: snapshotURL)

/Persistence/Disk Persistence/Snapshot/Snapshot.swift (line 91)
https://github.com/mochidev/CodableDatastore/blob/b02fdbaca2048079e9f0027d89e6914b2be63137/Sources/CodableDatastore/Persistence/Disk%20Persistence/Snapshot/Snapshot.swift#L91C54-L91C54

from codabledatastore.

pnewell avatar pnewell commented on June 26, 2024

Here is a more full, simple example using the latest release (0.0.29). This example with just two files runs fine on first run, but fails on second run. I am using Xcode 15 beta 4 and have. tried the iOS simulator and building for Mac:

Persistence.swift

import CodableDatastore

final class Persistence {
  func write() async throws {
    enum Version: Int, CaseIterable {
      case zero
    }
    
    struct TestStruct: Codable, Identifiable {
      var id: String
      var value: String
    }
    
    let persistence = try DiskPersistence.defaultStore()
    
    let datastore = Datastore.JSONStore(
      persistence: persistence,
      key: "test",
      version: Version.zero,
      migrations: [
        .zero: { data, decoder in
          try decoder.decode(TestStruct.self, from: data)
        }
      ]
    )
    
    try await datastore.persist(TestStruct(id: "3", value: "My name is Dimitri"))
    try await datastore.persist(TestStruct(id: "1", value: "Hello, World!"))
    try await datastore.persist(TestStruct(id: "2", value: "Twenty Three is Number One"))
    
    let count = try await datastore.count
  }
}

TestApp.swift

import SwiftUI

@main
struct CodableDatastore29App: App {
  var store = Persistence()
  
    var body: some Scene {
        WindowGroup {
            EmptyView()
            .task {
              try! await store.write()
            }
        }
    }
}

from codabledatastore.

dimitribouniol avatar dimitribouniol commented on June 26, 2024

Good catch! I'm embarrassed to say that I haven't written any tests that re-load the entire datastore from disk yet, so I fully expect you to find more issues 😅

from codabledatastore.

dimitribouniol avatar dimitribouniol commented on June 26, 2024

Told you I'd find more 😅:

from codabledatastore.

Related Issues (20)

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.