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

Metadata should be read/write capable independently #56

Merged
merged 3 commits into from Oct 13, 2015

Conversation

danthorpe
Copy link
Owner

Currently I can write my Item without writing its Metadata by setting the metadata property to nil, there's no way to conversely write the Metadata without also writing the Item.

There also doesn't appear to be a way to read either one without reading them both. This may seem odd, given that my original request was that I wanted to be able to read them together, which I now can, but I'd still like to be able to read them separately if needed.

Neither of these are really that big of a deal and may just be me prematurely optimizing, but as I'm refactoring my code to use the new API these have come up and I thought I'd run them by you.

@danthorpe
Copy link
Owner

Yeah, that's all a fair point. The functional API got scaled back in a few places, including the readMetadataAtIndex: function. Will add it back.

@danthorpe danthorpe modified the milestone: 2.2 Oct 13, 2015
@danthorpe
Copy link
Owner

So, I'll add readMetadata APIs, but don't probably will not add the API to read the object without the metadata. Unless that's an argument with default on the primary readAtIndex and readAtKey.

@danthorpe
Copy link
Owner

Also, just to clarify, YapDatabase doesn't support writing the metadata without writing the object. From the docs, it says if you pass nil for the object, it will remove the object from the database. So, I will not add a writeMetadata API.

Also, it is not possible to have a readMetadataByKey API, as the collection cannot be inferred from the MetadataType alone. While it is possible to write the function, using the object type, and returning the nested Object.MetadataType. However, when it comes to calling such a method, it will not work as I guess the compiler cannot infer the parent type from nested types. For example, given a function (which will compile)

func readMetadataByKey<
    PersistableWithObjectMetadata where
    PersistableWithObjectMetadata: Persistable,
    PersistableWithObjectMetadata.MetadataType: NSCoding>(key: String) -> PersistableWithObjectMetadata.MetadataType? {
        return readMetadataAtIndex(PersistableWithObjectMetadata.indexWithKey(key))
}

trying to use it...

let metadata: MyObject.MetadataType? = readMetadataByKey(aKey)

will not compile. So, instead, you'd have to call readMetadataAtIndex directly.

let metadata: MyObject.MetadataType? = readMetadataAtIndex(MyObject.indexWithKey(aKey))

@codecov-io
Copy link

Current coverage is 82.61%

Merging #56 into development will increase coverage by +0.98% as of bffd021

@@            development     #56   diff @@
===========================================
  Files                18      22     +4
  Stmts              1165    1231    +66
  Branches              0       0       
  Methods                               
===========================================
+ Hit                 951    1017    +66
  Partial               0       0       
  Missed              214     214       

Review entire Coverage Diff as of bffd021

Powered by Codecov. Updated on successful CI builds.

danthorpe added a commit that referenced this pull request Oct 13, 2015
Metadata should be read/write capable independently
@danthorpe danthorpe merged commit 4595861 into development Oct 13, 2015
@aranasaurus
Copy link
Contributor Author

Yap database doesn't have a writeMetadata.. but does have a replaceMetadata... method, which makes sense since you can't write a metadata by itself unless it already exists attached to an object.

Makes sense to have to use the full index to get the metadata separately as well, thanks for that!

@danthorpe
Copy link
Owner

@aranasaurus well, may add a set of replace functions at some point in the future.

@danthorpe danthorpe deleted the feature/YDB-56_read_metadata_only branch October 21, 2015 13:46
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

Successfully merging this pull request may close these issues.

None yet

3 participants