Listing db objects

14 views
Skip to first unread message

Regadas

unread,
May 28, 2011, 9:20:23 AM5/28/11
to highchair-user
Hi there,

I'm new to highchair and I had little time to go through the source.
While i was doing it I didn't saw any explicit way to list entities
and limit the number of records returned.

Did I missed something?

Thx for your help.

chris

unread,
May 28, 2011, 9:44:03 AM5/28/11
to highchair-user
Hi!

Are you asking for a count query that simply results in the number of
records matching a query, without actually fetching the records? If
so, the answer is no, that isn't currently supported. If you are
fetching the records, then obviously you can know the size because you
get a List[E] of results.

However, the current design of the query interface restrictive and
overall not very good - I've opened a ticket to address this. Is this
a feature you need immediately? The API will be changing, but If you
really need it I can probably push an intermediate change.

-chris

Regadas

unread,
May 28, 2011, 11:49:48 AM5/28/11
to highchair-user
The count thing would be great ... however what i was thinking was
more like Person.find(None).limit 100 ... this would list all persons
in db but limits the fetch to 100 rows.

chris

unread,
May 28, 2011, 1:09:42 PM5/28/11
to highchair-user
Ok, limits and offsets. These are supported by the datastore - I'll
get started on these in the process of reworking the API - expect at
least some progress today (I'm in tz GMT-5). These changes will happen
on master, so hopefully you're open to doing some early testing :-).

-chris

chris

unread,
May 29, 2011, 8:08:02 AM5/29/11
to highchair-user
I pushed some early code late last night that reworks the DSL and
provides for limits and offsets; see branch 004 (changed my mind about
master). The code is still early so treat it as volatile, but I like
how the dsl is looking (shamelessly like rogue). Here's an example
from the new spec (http://lssn.me/S6k):

Person where(_.lastName is "Lewis") fetch(limit = 1)

I know you're looking for a kind of find all query - it's not there
yet but I'm thinking of something like:

Person fetch()

I think that'd be simple enough, where you just fetch() on a Kind.
I'll be hacking a bit more on this today, so do test/share/hack and
give any feedback you'd like.

sincerely,
chris

chris

unread,
May 29, 2011, 8:09:03 AM5/29/11
to highchair-user
Arg - url got mangled. It is: http://lssn.me/S6k

chris

unread,
May 29, 2011, 3:58:37 PM5/29/11
to highchair-user
Ok, 004 now has a new and mostly stable api supporting key-only
queries, find-all, limits, and offsets. Have a look and tell me what
you think; here's how your example would be written:

Person fetch(limit = 100) // first 100 in db
Person fetch(100, 10) // first 100 in db, skipping the first

If you want to emulate a count query:

Person fetchKeys() size

That will run an efficient key-only query, and size gives the size of
the collection.

These methods act on any query, so you can constrain them:

Person where (_.firstName is "Regadas") fetch(limit = 10) // first 10
people with the first name "Regadas"

-chris

On May 28, 11:49 am, Regadas <filiperega...@gmail.com> wrote:

Regadas

unread,
May 30, 2011, 12:47:26 PM5/30/11
to highchair-user
Hi chris,

Looks nice :) I'll test it this evening!

Any special consideration that I need hove in order to build it?

Cheers,

chris

unread,
May 30, 2011, 2:50:48 PM5/30/11
to highchair-user
If you're using sbt it's really easy to use or build highchair.
Snapshots for 0.0.4 just reached the scala-tools snapshot repository,
so if you have the repo:

val stSnapshots = "Scala Tools Snapshots" at "http://scala-tools.org/
repo-snapshots/"

Then all you have to do as add a dependency to 0.0.4 (datastore
module, if that's all you want):

val h_datastore = "net.thegodcode" %% "highchair-datastore" % "0.0.4-
SNAPSHOT"

I'll get the wiki updated soon - let me know if you have any issues.
Thanks for using it!

-chris

Regadas

unread,
May 30, 2011, 3:02:57 PM5/30/11
to highchair-user
Yup I'm using sbt :)

Nice move getting it to the snapshots repo so fast :)

I'll let you know about the app i'm making ... i think all of us
(scala users) will find it usefull (at least I hope so)

Thx

Chris Lewis

unread,
May 30, 2011, 4:11:08 PM5/30/11
to highcha...@googlegroups.com
Cool! Can't wait to hear about it!
Reply all
Reply to author
Forward
0 new messages