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

[NFR] Query\Builder support INSERT/UPDATE/DELETE #1925

Closed
iwai opened this issue Jan 27, 2014 · 22 comments
Closed

[NFR] Query\Builder support INSERT/UPDATE/DELETE #1925

iwai opened this issue Jan 27, 2014 · 22 comments
Labels

Comments

@iwai
Copy link

@iwai iwai commented Jan 27, 2014

I tried to think of a new method, but how about you??

# INSERT INTO Cars (price, type) VALUES (:price:, :type:)
$result = $this->modelsManager->createBuilder()
   ->insert('Cars', array('price' => 15000.00, 'type' => 'Sedan'))
   ->getQuery()
   ->execute();

# UDPATE Cars SET price = :price, type = :type: WHERE id = :id:
$result = $this->modelsManager->createBuilder()
   ->update('Cars', array('price' => 15000.00, 'type' => 'Sedan'))
   ->where('id = :id:', array('id' => 100))
   ->getQuery()
   ->execute();

# DELETE FROM Cars WHERE id = :id:
$result = $this->modelsManager->createBuilder()
   ->delete('Cars')
   ->where('id = :id:', array('id' => 100))
   ->getQuery()
   ->execute();

## Or alternate concept

# INSERT INTO Cars (price, type) VALUES (:price:, :type:)
$result = $this->modelsManager->createBuilder()
   ->insert('Cars', array('price', 'type'), array(15000.00, 'Sedan'))
   ->getQuery()
   ->execute();

# UDPATE Cars SET price = :price, type = :type: WHERE id = :id:
$result = $this->modelsManager->createBuilder()
   ->update('Cars', array('price', 'type'), array(15000.00, 'Sedan'))
   ->where('id = :id:', array('id' => 100))
   ->getQuery()
   ->execute();

Method return is Phalcon\Mvc\Model\Query\Status.

I'm afraid my expressions may be rude or hard to read, because I'm not so good at English.

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@boast
Copy link

@boast boast commented Jan 28, 2014

+1 Looks really nice.

@niden niden added the Unassigned label Feb 19, 2014
@niden niden added Unassigned and removed New Feature Request labels Apr 3, 2014
@braska
Copy link

@braska braska commented Jul 26, 2014

+1

2 similar comments
@WooDzu
Copy link
Contributor

@WooDzu WooDzu commented Sep 7, 2014

👍

@atnartur
Copy link

@atnartur atnartur commented Sep 23, 2014

+1

@kbtz
Copy link

@kbtz kbtz commented Sep 23, 2014

😍

@mrenigma
Copy link

@mrenigma mrenigma commented Sep 28, 2014

+1 Would be amazingly useful for batch processing!

@posthy
Copy link

@posthy posthy commented Sep 29, 2014

+1

2 similar comments
@brainiac84
Copy link

@brainiac84 brainiac84 commented Oct 22, 2014

+1

@nejtr0n
Copy link

@nejtr0n nejtr0n commented Jan 22, 2015

+1

@collinswang
Copy link

@collinswang collinswang commented Mar 27, 2015

how to collect this issue?

@vitalypanait
Copy link

@vitalypanait vitalypanait commented Apr 24, 2015

+1

4 similar comments
@icedeng
Copy link

@icedeng icedeng commented May 28, 2015

+1

@armageddon-cat
Copy link

@armageddon-cat armageddon-cat commented Jun 16, 2015

+1

@salyakhov-art
Copy link

@salyakhov-art salyakhov-art commented Jun 16, 2015

+1

@sergeyklay
Copy link
Member

@sergeyklay sergeyklay commented Jun 17, 2015

+1

@ryomo
Copy link
Contributor

@ryomo ryomo commented Aug 26, 2015

delete() and update() are already implemented, right?

$this->modelsManager->createBuilder()
    ->from('Cars')
    ->where('type = :type:', array('type' => 'Sedan'))
    ->getQuery()
    ->execute()  // This returns Phalcon\Mvc\Model\Resultset
    ->delete();

The above is equivalent to the following PHQL.

$phql = 'DELETE FROM Car WHERE type = :type:';
$query = new Query($phql, Di::getDefault());
$query->execute(['type' => 'Sedan']);

Both of 2 got same SQL statements. (PHQL also calls DELETE FROM ~ many times.)

SELECT `car`.`id`, `car`.`type` FROM `car` WHERE `car`.`type` = :0
SAVEPOINT PHALCON_SAVEPOINT_2
DELETE FROM `car` WHERE `id` = ?
DELETE FROM `car` WHERE `id` = ?
DELETE FROM `car` WHERE `id` = ?
...
RELEASE SAVEPOINT PHALCON_SAVEPOINT_2

refer

@JigneshPansuriaDeveloper

this above delete and update not working for non primary key.

@Firzenizer
Copy link

@Firzenizer Firzenizer commented Mar 31, 2016

Damn I was just looking for this feature. Seems it doesn't exist. I was looking to update using inWhere()

@Jurigag
Copy link
Member

@Jurigag Jurigag commented May 8, 2016

@ryomo

It's not implemented, is just selecting first and then deleting. I think there shouldn't be selecting.

@dictbox
Copy link

@dictbox dictbox commented Feb 19, 2017

+1

@dictbox
Copy link

@dictbox dictbox commented Feb 19, 2017

Laravel support similar function。

@stale
Copy link

@stale stale bot commented Apr 16, 2018

Thank you for contributing to this issue. As it has been 90 days since the last activity, we are automatically closing the issue. This is often because the request was already solved in some way and it just wasn't updated or it's no longer applicable. If that's not the case, please feel free to either reopen this issue or open a new one. We will be more than happy to look at it again! You can read more here: https://blog.phalconphp.com/post/github-closing-old-issues

@stale stale bot added the stale label Apr 16, 2018
@sergeyklay sergeyklay closed this Apr 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet