Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 3: Update interfaces and nothing else #108

Closed
pmjones opened this issue Sep 20, 2016 · 18 comments
Closed

Version 3: Update interfaces and nothing else #108

pmjones opened this issue Sep 20, 2016 · 18 comments

Comments

@pmjones
Copy link
Member

pmjones commented Sep 20, 2016

There have been several questions lately regarding the fact that the interfaces do not match the classes. The disconnect is because the classes have had features added, but adding the relevant methods to the interface would be a BC break.

Perhaps the time has come to update the interfaces, and in so doing move to version 3, with no other functionality changes.

Thoughts?

@cdekok
Copy link

cdekok commented Oct 3, 2016

If you plan to change it you might want to consider changing the split with SubSelectInterface and SelectInterface it's a bit annoying you cannot get any typehint as you can only typehint on one of interfaces please consider extending the interface for ease of use with an IDE.

@pavarnos
Copy link
Contributor

pavarnos commented Dec 11, 2016

Yes please!
Also fix col() which is yellow in phpStorm with 2 arguments.

I have ended up creating a small wrapper class that fixes some annoyances and adds extra utility functions. For example, adding the ability to include columns from the join table that get automatically prefixed by the table name, a joinLeft() / joinInner(), and extra methods to ease working with subselects (not shown below).

class WrappedSelect {
   /** @var Aura\SqlQuery\Common\SelectInterface */
   private $select;

    /**
     * Adds a JOIN table and columns to the query.
     * @param string       $joinType  The join type: inner, left, natural, etc.
     * @param string       $spec      The table specification; "real_table" or "real_table AS alias" 
     * @param string       $condition Join on this condition.
     * @param array        $columns   columns as passed to cols()
     * @return $this
     */
    public function join($joinType, $spec, $condition = null, $columns = null)
    {
        $this->select->join($joinType, $spec, $condition);
        $this->addColumns($columns, $spec);
        return $this;
    }

    /**
     * @param string $spec      The table specification; "foo" or "foo AS bar".
     * @param string $condition Join on this condition.
     * @param array  $columns   columns as passed to cols()
     * @return $this
     */
    public function joinLeft($spec, $condition = null, $columns = [])
    {
        return $this->join('left', $spec, $condition, $columns);
    }

    /**
     * Adds a FROM element to the query; quotes the table name automatically.
     * @param string $table The table specification; "foo" or "foo AS bar".
     * @param array  $columns
     * @return $this
     */
    public function from($table, $columns = [])
    {
        $this->select->from($table);
        $this->addColumns($columns, $table);
        return $this;
    }

    /**
     * @param array  $columns
     * @param string $tableName table name
     */
    private function addColumns($columns, $tableName)
    {
        if (empty($columns)) {
            return;
        }
        if (strpos($tableName, ' ') !== false) {
            // if the table spec is a subselect or function or anything funky then just add the raw columns
            $this->cols($columns);
            return;
        }
        $resolved = [];
        foreach ($columns as $col => $alias) {
            if (is_string($col)) {
                $col = $tableName . '.' . $col;
            } else if (!preg_match('|[.("]|', $alias)) {
                // no function call or other weirdness
                $alias = $tableName . '.' . $alias;
            }
            $resolved[$col] = $alias;
        }
        $this->cols($resolved);
    }

// ... etc

@pavarnos
Copy link
Contributor

Can we also make several protected methods public and available via the interface? eg reset() and the build* functions, or provide getters for flags (for DISTINCT), groupBy, orderBy, having.

I recently built a paginator class that builds a PageInformation data transfer object for a sliding window of pages. Its based on ZF1, ZF2, PagerFanta and jasongrimes/php-paginator. But none of the above support Aura, and seem quite complex for what is actually needed. With the above changes, i can make the paginator even cleaner / clearer and offer it to the Aura project if you want it.

paginator

@pavarnos
Copy link
Contributor

can you create a v3 branch we can make pull requests against?

@harikt
Copy link
Member

harikt commented Dec 29, 2016

@pavarnos have created a 3.x branch.

@pmjones pmjones closed this as completed Dec 29, 2016
@pmjones pmjones reopened this Dec 29, 2016
@pavarnos
Copy link
Contributor

pavarnos commented Dec 31, 2016

a suggested "ship list" for v3?

I'm OK with doing all this: i have time this week. @harikt has been great at responding quickly.

@harikt
Copy link
Member

harikt commented Jan 1, 2017

@pavarnos I would suggest you to create separate PR's . Small PR's are easy to review and merge. Changes to interfaces in PR may take some time for review and getting merged.

I will try my best to respond / merge with my knowledge.

Thank you.

@harikt
Copy link
Member

harikt commented Jan 1, 2017

By the way the docs structure will change. I will make the changes soon.

@syrm
Copy link

syrm commented Jan 27, 2017

Don't forget to add hasCols and getCols in interface ;)

@pavarnos
Copy link
Contributor

@OXman see #112: just waiting on approval / merge. Its a big PR though...

@pmjones
Copy link
Member Author

pmjones commented Feb 19, 2017

@pavarnos et al: I've just merged a bunch of 3.x-related stuff; let me know how much that moves the checklist forward.

@pavarnos
Copy link
Contributor

thanks for all the merges. updated the checklist. i'm short of time to contribute much for the next wee while...

@pmjones
Copy link
Member Author

pmjones commented Feb 19, 2017

@pavarnos No hurry on my part. Thanks to you and @harikt for all your work here!

@pmjones
Copy link
Member Author

pmjones commented Mar 19, 2017

My apologies, folks -- my recent PRs to the 3.x branch have been over-and-above this plan. After the Quoter PR I will cease, and move on to documentation.

Further, I think the Subselect interface can be merged to SelectInterface, so long as we typehint that particular bit of logic to SelectInterface instead of Subselect.

Thoughts?

@pavarnos
Copy link
Contributor

pavarnos commented Mar 19, 2017 via email

pmjones pushed a commit that referenced this issue Mar 20, 2017
@harikt
Copy link
Member

harikt commented Mar 21, 2017

UPDATE : I have made the 3.x as default branch.

@pavarnos
Copy link
Contributor

all the things in this issue have now been resolved? can it be closed?

@pmjones
Copy link
Member Author

pmjones commented Apr 20, 2017

Looks like it.

@pmjones pmjones closed this as completed Apr 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants