Code Monkey home page Code Monkey logo

sprouch's People

Contributors

kimstebel avatar

Stargazers

 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

sprouch's Issues

keyRange doesn't accept non-String keys

I have a key that looks like this:

val key = (1326974400000L, "67bb5d5f2fddbea2bf24a29a5f004da5")

The Long there is a date-time emitted to the CouchDB index so that a sequential number could be used at the front of a compound key in order to sort the results in reverse-chronological order. I believe it's a pretty common technique (and off the top of my head I'm not sure how else I'd accomplish the same).

I can't pass that key to queryView(startRange = Option[(String, String)]) though since it requires strings. I tried key.toJson.toString, but the encoding is off. While the toJson representation is correct, calling toString causes Sprouch to end up escaping the parameter to look like a string that contains a representation of a JSON Array, and not the actual Array key.

Best I can figure out anyway.

I don't see a way to pass the actual key at this point since the keyRange parameter requires a String, but any String I'd pass that would represent the Array would be doubly-escaped by Sprouch.

Since the range you're querying should conform to the K value you passed to queryView, it seems like modifying https://github.com/KimStebel/sprouch/blob/master/src/main/scala/sprouch/Database.scala#L198, which is:

keyRange:Option[(String,String)] = None

To:

keyRange:Option[(K,Option[K])] = None

Would be more correct?

Being able to specify None for the endKey also seems like a requirement, though honestly I wouldn't complain if the CouchDB API were followed a bit closer and startKey and endKey were separate parameters instead of a Range, which seems wrong since currently you have to pass an empty String for the endKey if you don't want to specify it (which seems more common than not to me).

include_docs flag does not trigger processing of emitted doc field

When using include_docs, the CouchDB view will emit additional information, including a doc field containing the document. This field appears to be ignored by Sprouch, so a queryView[K,V] call will return MalformedContent exceptions.

If you call queryView[K, Option[V]] it'll work since value is null, but then you result.rows.map(_.value).flatten and you realize that the document isn't actually used and instead Sprouch tried to convert your empty value fields to Option[V], which resulted in setting them all to None.

See below:

http://ssmoot.cloudant.com/blog/_design/posts/_view/all?descending=true&include_docs=true&limit=10

It's important to note that the value fields are null, because the (CouchDB) map() doesn't emit the document explicitly. This is a common performance optimization for indexing so the entire document isn't indexed, but you can still get it back (through the use of include_docs).

I can't think of a good reason to use value instead of doc when include_docs is passed, so that would seem like the correct thing to do to me.

As a temporary workaround, you can emit the document in CouchDB, but that really defeats the point of passing include_docs.

It could also be that Sprouch allows you to explictly parse the document? I haven't seen an example of that, but I haven't traced the code yet either. Something like the following I imagine:

db.queryView[String,String]("posts", "all", ViewQueryFlag(include_docs = true), limit = Some(10)).map { result =>
  result.rows.map { row =>
    Post(Json.parse(row.value) \ "doc")
  }
}

Maybe the right thing to do would be to include a doc field on a RevvedDocument. Dunno.

ViewQueryFlag apply builds a Set of all options explicitly

This code:

val flags = ViewQueryFlag(descending = true, include_docs = true)

Will return:

Set[sprouch.ViewQueryFlag] = Set(inclusive_end, include_docs, descending, reduce)

None of those are CouchDB defaults, so the deviation in query-API defaults by Sprouch is frustrating.

To return to default/expected behavior you need to pass something like this to your Database.queryView() call instead:

import sprouch.ViewQueryFlag._
val flags = Set[ViewQueryFlag](descending, include_docs)

That will avoid unnecessarily pulling in options you didn't specify. It would be convenient if ViewQueryFlag.apply() only passed the intended options though since the first example is what's demonstrated in the tutorials.

Need way to getDoc on an id that may not exist

Right now if you try to run something like:

db.getDoc[User]("key does not exist")

Sprouch throws an exception.

If you can't guarantee a document is going to exist, then you basically need to use a query instead. (I think.) From a practical POV, you can't really ever guarantee a particular document id exists.

Anyways, it would be nice if getDoc returned an Option[A] instead. Or make RevedDocument support isDefined/map/filter/fold.

I'm not sure what the best course is. Just something that will skip the exception but not round-trip would be nice.

No ability to set language for Views

Cloudant supports "search" as a language. The standard CouchDB implementation supports CoffeeScript. It would be nice to be able to pass the language for views so I can use Sprouch to define my Views.

I think a required string argument for language would be fine personally. An Enum seems cool too, but that limits your ability to deploy alternative View engines.

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.