Closed nathggns closed 11 years ago
This fixes #85
Using Database::func_random()
isn't too nice. Would be nice to have maybe something like the following, not sure if it's possible.
<?php
$user->random([]);
Where the array would be the where clauses.
I never said that helpers like that wouldn't be possible, you could even define those yourself. I'll define some later, including that one.
However, I was thinking of using __call for functions as columns.
Ah. Awesome.
@AndrewHathaway You can now pass functions to ModelDatabase by simply calling the function. ModelDatabase::max
for example. You can pass arguments too.
@ClaudioAlbertin Question. Should aliases functions be part of the export array?
Nice work. :)
The random function uses the preexisting conditions. Set conditions, then use random.
Merging. Any complaints about this implementation should be made in a separate issue.
These commits add SQL function support across Scaffold's database system.
Usage
Changelog
This pull request added the following two classes.
DatabaseQueryBuilderFunction
SQLite => 'SQL
).DatabaseQueryBuilderFunctionRandom
random
) to generate the string. Instead, it returns a custom stringRAND
. We'll probably need to add a lot more of these.It adds the following service
database.query.builder.function
DatabaseQueryBuilderFunction
class.Database::__construct
has been modified to not need an instance of Config passed to it if it has been initiated before.Dynamic
has been modified to support being an alias for a class method. Simply pass the same array you'd pass tocall_user_func
The following methods have been added
Database::func_*
as
, which allows you to alias the function (generating SQL strings likeSELECT COUNT(*) AS
countFROM ...
)DatabaseQueryBuilder::val
vals
section ofquery_opts
for SELECT statements.DatabaseQueryBuilder::is_func
DatabaseQueryBuilder::func
ModelDatabase::value
__get
is now an alias for this. We can now pass function objects to it. Results of functions will never be cached.ModelDatabase::alias
ModelDatabase::__call
__call
will create function objects with the name of the function and any args passed to it, which is then passed toModelDatabase::func
(The function thatModelDatabase::value
uses for function objects)ModelDatabase::random
The following bugs have been fixed
Database::__callStatic
successfully passes unknown functions through to the driver.