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

Comments

Projects
None yet
@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

This comment has been minimized.

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

This comment has been minimized.

braska commented Jul 26, 2014

+1

2 similar comments
@WooDzu

This comment has been minimized.

Contributor

WooDzu commented Sep 7, 2014

👍

@atnartur

This comment has been minimized.

atnartur commented Sep 23, 2014

+1

@csguimraes

This comment has been minimized.

csguimraes commented Sep 23, 2014

😍

@mrenigma

This comment has been minimized.

mrenigma commented Sep 28, 2014

+1 Would be amazingly useful for batch processing!

@posthy

This comment has been minimized.

posthy commented Sep 29, 2014

+1

2 similar comments
@brainiac84

This comment has been minimized.

brainiac84 commented Oct 22, 2014

+1

@nejtr0n

This comment has been minimized.

nejtr0n commented Jan 22, 2015

+1

@collinswang

This comment has been minimized.

collinswang commented Mar 27, 2015

how to collect this issue?

@vitalypanait

This comment has been minimized.

vitalypanait commented Apr 24, 2015

+1

4 similar comments
@icedeng

This comment has been minimized.

icedeng commented May 28, 2015

+1

@armageddon-cat

This comment has been minimized.

armageddon-cat commented Jun 16, 2015

+1

@ZoorGan

This comment has been minimized.

ZoorGan commented Jun 16, 2015

+1

@sergeyklay

This comment has been minimized.

Member

sergeyklay commented Jun 17, 2015

+1

@ryomo

This comment has been minimized.

Contributor

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

@jigneshnavsoft

This comment has been minimized.

jigneshnavsoft commented Sep 9, 2015

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

@Firzenizer

This comment has been minimized.

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

This comment has been minimized.

Member

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

This comment has been minimized.

dictbox commented Feb 19, 2017

+1

@dictbox

This comment has been minimized.

dictbox commented Feb 19, 2017

Laravel support similar function。

@stale

This comment has been minimized.

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