Giter Club home page Giter Club logo

sql's People

Contributors

alexgisby avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

koreanbbque

sql's Issues

Join with alias

I tried to find a way to add a "JOIN" with an alias for the table. I only found the following way to implement this:

    $query->join(new Expression('`location` AS `work`'), 'work.id', '=', 'users.work_location_id');
    $query->join(new Expression('`location` AS `home`'), 'home.id', '=', 'users.home_location_id');

Using an expression does not seem to be the intended way for this, especially as quoting is not based on the given dialect.

Would it be possible to implement a solution like this:

    $query->join(['work' => 'location'], 'work.id', '=', 'users.work_location_id');

or like the workaround I am using now (the class Alias implements the ExpressionInterface for this):

    use Dialect\MySQL\Alias;
    //...
    $query->join(new Alias('location', 'home'), 'home.id', '=', 'users.home_location_id');

Or is there an implementation, which I missed?

Select->count() and other questions

I've spent days searching for a simple / clean sql query builder that is unit tested, psr-compliant, extensible, does not need a PDO connection, and without any unusual weirdness. Delighted to stumble across your package this morning. It looks awesome. Thanks for making it available.

Was thinking about making a pull request for a couple of new features, but wanted to check in with you first to see if the idea is worth pursuing...

Pagination:
https://github.com/whiteoctober/Pagerfanta and similar need 2 things to create a paginator: the total number of rows in the full result set, and a way to slice out just the current page. Adding something like

 public function count()
    {
        $parts = [
            'select count(*) as row_count',
            $this->buildFromSQL(),
            $this->buildJoinSQL(),
            $this->buildWhereSQL($this->dialect),
            $this->buildGroupBySQL(),
            $this->buildHavingSQL($this->dialect)
        ];
        return join(" ", array_filter($parts));
    }

just below Select->sql() would make it super easy to create an adapter class and would mean you don't have to clone the Select just to change the columns and drop off the order / limit.

Engine / driver specific flags:
Aura SQL https://github.com/auraphp/Aura.SqlQuery#mysql-query-objects-mysql allows you to inject flags into the query (eg for MySQL: INSERT DELAYED, SELECT DISTINCT, SELECT SQL_SMALL_RESULT). Adding a trait to collect flags

trait Flags {
    /** @var string[] simple array of flag names inserted into the query */
    private $flags = [];

    public function addFlag($flag) {
        $this->flags[]= $flag;
        return $this;
    }

    public function getFlags() {
        return join(' ', $this->flags);
    }
    // ... etc
}

would allow the injection of arbitrary driver specific flags in buildSelectSQL(), buildInsertSQL() etc to tune performance. Your code could just treat them as arbitrary strings injected and not care what they contain.

REPLACE or ON DUPLICATE KEY UPDATE
Again these are MySQL specific syntax, but the ability to change the name of the sql command in Insert->sql() from 'INSERT INTO' to 'REPLACE INTO' would be nice. Or the creation of a new class InsertOrUpdate.php that was able to do 'on duplicate key update' style queries.

Would you accept pull requests for any or all of the above?

INTO OUTFILE?

Is it possible to parse SELECT ... INTO OUTFILE ... queries?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.