Commit graph

93 commits

Author SHA1 Message Date
Josh Sherman
d96181c60f Q4 2013, seemed like a good time to update the copyright notices 2013-11-04 17:36:04 -05:00
Josh Sherman
058e22c1aa Made method public and fixed return 2013-10-02 15:59:48 -04:00
Josh Sherman
011f9b42b2 Updated to not store empty cache
Primary key queries should not be cached because the record may not exist today but could exist in the future and because the INSERT logic in PICKLES doesn't do any invalidation of the cache.
2013-09-27 13:40:44 -04:00
Josh Sherman
7ed930d278 Fixed issue when passing in single IDs
If you tried to use the extended array syntax to query against the primary key (id) and passed it an integer instead of an array, an error was occurring. Thanks @geoffoliver !
2013-09-22 22:48:07 -04:00
Josh Sherman
dd6ba92e28 Added utility method to extract values from field
Pass it a field name, it'll return an array of all of the values form that field.
2013-09-16 12:59:16 -04:00
Josh Sherman
38e5173823 Updated checks for exactly false.
Fixed some issue withe the sanity checks if the cache results.
2013-09-15 23:32:34 -04:00
Josh Sherman
919ad37717 Added arbitrary cache usage by key.
Pass a Model an optional second or third parameter to force the Model to check the cache before running the query and stashing the results in the key for future queries.
2013-09-15 17:15:22 -04:00
Josh Sherman
dca62b82d1 Removed unnecessary sanity checks when calling Log 2013-09-15 12:02:07 -04:00
Josh Sherman
b6bacdd432 Caching where primary key in ( ... )
Caching was limited to single row selects against the primary key. Expanded to include cache checking and storing when selecting multiple values against the primary key. Does not work on any other row due to the fact that some rows may have duplicate values and the mapping could get borked pretty quick.
2013-09-15 11:56:34 -04:00
Josh Sherman
391e95c9e8 Reverted per column caching aside from id field.
Was a bit messy, just so hard to automagically cache stuff without knowing the data usage.
2013-09-13 13:22:10 -04:00
Josh Sherman
4819b2c1a2 Added sanity check for variable
I like to remove the password field from records when I'm not using the password value, this caused an error when creating the cache keys.
2013-09-11 10:28:38 -04:00
Josh Sherman
9dcf3fa58e Added column caching
If you're pulling data against a single column and returning a single column the UID will be cached out to a key that can easily be recalled the next time the same query is executed. On UPDATE and DELETE the corresponding keys are deleted.
2013-09-10 22:43:52 -04:00
Josh Sherman
d25b042d8e Revert "Reworked Database stuff to be Datastore stuff"
This reverts commit ebd0018473.
2013-02-26 15:14:17 -05:00
Josh Sherman
ebd0018473 Reworked Database stuff to be Datastore stuff
Wanted a generic grouping for all datastores so there's a place for memcached and redis.
2013-02-26 10:15:52 -05:00
Josh Sherman
fe0fd407cf Added inc/decrement functionality to the Model
Sure beats incrementing the variable then setting it! Usage: $model->record['column'] = '++'; // or '--'. Only works with single row updates at the moment. May expand into allowing a variable step to be defined (+10 or ++10 or something... I say that cause I think the double character is a bit safer since you could in theory set a value to -10000 and not want it to decrement by 10k)
2012-12-30 12:21:49 -05:00
Josh Sherman
3290ee0135 Added cache purging post-execution for multiple row UPDATEs 2012-12-02 13:08:36 -05:00
Josh Sherman
50664a22ac Added support for multiple UPDATEs
Also added a new parameter to allow for PDO to handle this correctly as Postgres doesn't allow for multiple row updates in a prepared statement
2012-12-02 12:58:06 -05:00
Josh Sherman
6f80fb51df Added a way to queue records and do a mass INSERT 2012-11-16 17:48:05 -05:00
Josh Sherman
6c7d48278c REPLACE syntax was still using SET even though the way variables were set has changed 2012-11-07 19:53:09 -05:00
Josh Sherman
a0ad85e8e9 Added ability to turn off database auto-cache from the config
Probably should make it a part of the model as well, assuming it doesn't already do that, pretty sure it doesn't. Would help me as one of my sites I need to migrate a ton of code, so being able to flip models on one by one would be excellent.
2012-11-06 11:21:02 -05:00
Josh Sherman
b41f2c12e9 Updated to check if the supposed column names are integers
Simplified logic by only checking one variable. Since "1" is a string but also returns true for being an integer, I swapped the is_string out for an !is_int
2012-11-06 09:13:55 -05:00
Josh Sherman
b2037343d9 Added ability to pass in an array of integers assumed to be ID's
Previously new Model(array(1, 2, 3)); would results in a query like SELECT * FROM table WHERE 1 AND 2 AND 3; which would typically result in an out of memory error depending on the number of rows in the table (as all would be returned). Added detection for an array of integers and forces that to be considered new Model(array('id' => array(1, 2, 3))). As I type this I think I need to go back and make an additional change.
2012-11-06 09:03:03 -05:00
Josh Sherman
99aa78b6fa Built in caching for primary key queries
Selects done against a primary key will automatically cache to Memcached (haven't tried it, but it should fail gracefully) indexed by the model name and the primary key ([NAMESPACE-]MODEL-PKEY). Any updates or deletes against the same primary key will purge the cache automatically. The major caveat here is the case of mass updates which would result in stale data. As it stands the data is being cached for a mere 5 minutes, so this multiple row update scenario would be short lived but ideally, I'll be pushing back the time to live on the cache and/or making it something that's configurable. If you have to do mass updates, you're probably doing them with a cronjob and should just be flushing all of the cache in that scenario (as it would be nearly impossible to detect the affected keys and purge them all).
2012-10-23 23:30:04 -04:00
Josh Sherman
dc0d98906f Added Model and configuration overrides for the column mapping
Also obliterated the getters and setters in the Database class after running some tests against their speed in comparison to getting and setting the variables directly
2012-10-22 10:23:10 -04:00
Josh Sherman
521deddc44 Added injection of is_deleted when doing a query 2012-10-13 11:02:02 -04:00
Josh Sherman
d76e2e71e9 Implemented created, updated, deleted logic.
Automatically inject the creation, update, and delete timestamps as well as which user performed the action. Rows can now be logically deleted and there are no more named parameters just question mark syntax.
2012-10-13 10:18:07 -04:00
Josh Sherman
e05dd7c79e Added check that the table variable is actually set 2012-10-11 21:35:28 -04:00
Josh Sherman
ce61f797f3 Added automatic injection of timestamps 2012-10-11 21:27:22 -04:00
Josh Sherman
a595d85857 Dropped ID variable for Columns
The ID variable was used to map the table's UID so the model could inject it in properly. Added a new variable named columns that is an array of the key columns. Currently contains ID, Created at and Updated at columns. The timestamp columns will soon be injected into the queries and if the value is set to false, will skip it.
2012-10-11 18:56:15 -04:00
Josh Sherman
252ad2fe7b Dropped MongoDB support
There wasn't much to drop as it was never fully integrated. Unfortunately the only things that end up being fully integrated are the things that I actually use. Maybe someday MongoDB, maybe someday.
2012-10-11 17:35:02 -04:00
Josh Sherman
6f114361bd Updated copyright, website and contact email 2012-09-30 12:40:29 -04:00
Josh Sherman
92fcfee986 PostgreSQL support 2012-09-30 12:18:25 -04:00
Josh Sherman
dc916622bb Added *_PRIORITY and IGNORE syntax
Expanded Model class to support queries with priorities as well as the ignore syntax. Priority can be set to LOW or HIGH and will be added to the appropriate queries with the appended _PRIORITY syntax. Ignore is boolean like the Delayed variable.
2011-11-20 13:32:35 -05:00
Josh Sherman
dd4fb702eb Ripped out Mongo code, it's not being used and not being developed against at this time. 2011-11-06 20:53:48 -05:00
Josh Sherman
9fa67d0717 Added logic to snapshot/recall the original object properties. 2011-11-02 22:49:53 -04:00
Josh Sherman
b39a6163e8 Moved logic to run the query out of the constructor. 2011-11-02 22:15:04 -04:00
Josh Sherman
575a2f0914 Commented out cache usage in Model. 2011-11-01 19:05:25 -04:00
Josh Sherman
baa291d88b Removed hashing based on some new caching logic I'm still dreaming up. 2011-10-30 22:09:12 -04:00
Josh Sherman
e104250597 Caching of simple queries against primary key. 2011-10-30 20:49:23 -04:00
Josh Sherman
4b96d28bb7 Added cache object to Model and cleaned up some variable names. 2011-10-30 19:24:23 -04:00
Josh Sherman
3ea9ec8f36 Added support for "REPLACE" SQL syntax. 2011-07-31 18:33:17 -04:00
Josh Sherman
b2504f5a6b Updated $db property to be protected instead of private to allow for "in model" interfacing with the object. 2011-05-21 00:28:14 -04:00
Josh Sherman
2ea8e1957d Fixed bug with commit() when no original record is set (in the case that you are running an update but did not pull the row beforehand). 2011-05-14 16:41:08 -04:00
Josh Sherman
996241debb Updated headers to have 2011 in the copyright date. Also updated copyright to my name as the LLC is currently defunct. 2011-05-09 22:14:55 -04:00
Josh Sherman
fb8a1f5894 Updated Model to allow ID value to be passed in either argument.
Existing functionality:
User(1); -- SELECT * FROM users WHERE id = 1;

New functionality:
OLD: User('count', 1) -- SELECT COUNT(*) AS count FROM users;
FIX: User('count', 1) -- SELECT COUNT(*) AS count FROM users WHERE id = 1;
2011-05-08 12:12:10 -04:00
Josh Sherman
a2f2e98195 Added reset to the walk() to save from calling reset() when iterating a record set more than once (hey, that shit happens!) 2011-04-02 12:55:29 -04:00
Josh Sherman
6bb94972b4 Added walk() method and scaffolding for sort() and shuffle() 2011-04-02 12:47:10 -04:00
Josh Sherman
8206239d59 Added model return type "indexed". Indexed returns are full recordsets, but they are indexed on the first value of the array. This will probably be expanded to allow for an index column to be defined as the 2nd or 3rd parameter. 2011-01-16 21:29:10 -05:00
Josh Sherman
861311a7f3 Cast variable as string so ctype_digit() will work. 2011-01-15 17:33:37 -05:00
Josh Sherman
bea6b0f645 Fixed issue when executing Model->commit() and no data has changed 2011-01-02 01:17:57 -05:00