Page 1 of 4

kQuery()->"a faster, smarter active record ;-)"

Posted: Fri Mar 09, 2007 1:31 pm
by Kieran Huggins
Hey all - I'm starting to build a new active record system in PHP modeled after jQuery, and I figured it would be a project that we could all help develop and use. I call it: kQuery ;-)

Each "kQuery" object would be a hash of data objects that certain operations can be applied to, much in the same way jQuery objects are a hash of javascript objects.

The syntax is essentially like this so far (think CSS2 selectors, sort-of):

Code: Select all

// select by id
kq('datatype #id'); //--> selects the data object (not just a row) with the id "id"

// comma separates cumulative queries
kq('datatype #id, datatype #id2'); //--> selects the 2 data objects with the ids "id" and "id2" 

// find by property
kq('datatype [property]'); //--> selects data objects that have this property

// find by property value
kq("datatype [property='value']"); //--> selects data objects where property = value

// find by value
kq("datatype [='value']"); //--> selects data objects where any property = value

// find by value test
kq("datatype [property>=5]");

// find by neg. value test
kq("datatype [property!='bob']");

//...and so on
Also, just like jQuery, these objects would be chain-able:

Code: Select all

echo kq('datatype #id')->each(strtoupper($this->name))->toXML();
So... who's with me?

NSG - I just know this looks appealing to you!

Posted: Fri Mar 09, 2007 1:48 pm
by RobertGonzalez
Man, as much as I'd love to jump into this, the only that comes to mind is

You crazy, foo!

Posted: Fri Mar 09, 2007 2:06 pm
by Luke
It certainly looks interesting.

Posted: Fri Mar 09, 2007 2:28 pm
by xinnex
I'm in if you add a "beta"-tag somewhere, and a flashy logo..

edit: A wiki? I'm in.. hand me an svn-account ;)

Posted: Fri Mar 09, 2007 2:59 pm
by Kieran Huggins
@xinnex: there will even be round corners and a wiki!

Posted: Fri Mar 09, 2007 3:55 pm
by Mightywayne
Impressive. o.o; Go for it.

Posted: Fri Mar 09, 2007 4:49 pm
by Luke
why not pQuery?

Posted: Fri Mar 09, 2007 11:06 pm
by Kieran Huggins
k comes after j.... also I'm a k :-)

I'm not all that vain though, we could call it nsgQuery!

Posted: Sat Mar 10, 2007 7:53 pm
by RobertGonzalez
I was thinking k because of:

Kieran, King of the Krazy Koders

Posted: Sun Mar 11, 2007 4:50 am
by brice
I for one would be interested to see your active record idea come to light -- kQuery's name has me believe that the datasets are in some way correlated to the DOM though. Our your ideas for real? Or is this some kind of joke? ;)

That aside, what are some of the better ActiveRecord/Object Mapping/CRUD data handling frameworks out there?

~ Brice

Posted: Sun Mar 11, 2007 9:16 am
by Ollie Saunders
How about kGoat? :)

Kieran, could you explain why this is useful/necessary? or have you just gone a bit jQuery mental?

Posted: Sun Mar 11, 2007 9:23 am
by Weirdan

Code: Select all

echo kq('datatype #id')->each(strtoupper($this->name))->toXML();
won't work because of lack of closures in PHP

Posted: Sun Mar 11, 2007 12:11 pm
by Kieran Huggins
@everah: It's so Krazy&tm; it just might work!

@Brice: It's totally inspired by jQuery, which primarily traverses the DOM. I'm developing a lot of XML datasets these days, so my mindset is stuck in that mode ;-) I'm totally serious and I'm prototyping this code now!

@ole: You know I'm totally jQuery mental! I've been totally sold on this theory of "find things and do stuff" and I think it would work equally well with data objects - It just speaks to me (and is drowning out the other voices in my head ATM).

I'm not totally crazy here (or at least not alone in my delusions)... After doing some research it seems NExT developed something similar called Enterprise Objects which eventually became webObjects in OS X.

@Weirdan: Boo-urns :-( ...but what about: http://tinyurl.com/yt3hy5 and http://blinkinglights.org/php/Closure.php ?

Posted: Sun Mar 11, 2007 12:24 pm
by feyd
Just use callbacks and be done with it.

Posted: Sun Mar 11, 2007 1:55 pm
by Kieran Huggins
@feyd: You're completely correct, maybe the example code should have read:

Code: Select all

echo kq('datatype #id')->each('strtoupper',array('$this->name'))->toXML();
My brain is starting to hurt :-(

At least the selection syntax could save some time... but I do hope it will grow to be more!