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

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

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

Post 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!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Man, as much as I'd love to jump into this, the only that comes to mind is

You crazy, foo!
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

It certainly looks interesting.
User avatar
xinnex
Forum Commoner
Posts: 33
Joined: Sun Jan 07, 2007 7:38 pm
Location: Copenhagen, Denmark

Post 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 ;)
Last edited by xinnex on Fri Mar 09, 2007 4:31 pm, edited 1 time in total.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

@xinnex: there will even be round corners and a wiki!
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

Post by Mightywayne »

Impressive. o.o; Go for it.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

why not pQuery?
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

k comes after j.... also I'm a k :-)

I'm not all that vain though, we could call it nsgQuery!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I was thinking k because of:

Kieran, King of the Krazy Koders
brice
Forum Newbie
Posts: 1
Joined: Sat Mar 10, 2007 8:02 pm

Post 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
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

How about kGoat? :)

Kieran, could you explain why this is useful/necessary? or have you just gone a bit jQuery mental?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Code: Select all

echo kq('datatype #id')->each(strtoupper($this->name))->toXML();
won't work because of lack of closures in PHP
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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 ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Just use callbacks and be done with it.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post 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!
Post Reply