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
stale Stale issue - automatically closed

Comments

@iwai
Copy link

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 commented Jan 28, 2014

+1 Looks really nice.

@braska
Copy link

braska commented Jul 26, 2014

+1

2 similar comments
@pgasiorowski
Copy link
Contributor

👍

@atnartur
Copy link

+1

@kbtz
Copy link

kbtz commented Sep 23, 2014

😍

@mrenigma
Copy link

+1 Would be amazingly useful for batch processing!

@posthy
Copy link

posthy commented Sep 29, 2014

+1

2 similar comments
@brainiac84
Copy link

+1

@nejtr0n
Copy link

nejtr0n commented Jan 22, 2015

+1

@collinswang
Copy link

how to collect this issue?

@vitalypanait
Copy link

+1

4 similar comments
@icedeng
Copy link

icedeng commented May 28, 2015

+1

@armageddon-cat
Copy link

+1

@salyakhov-art
Copy link

+1

@sergeyklay
Copy link
Member

+1

@ryomo
Copy link
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

@JigneshPansuriaDeveloper

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

@Firzenizer
Copy link

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

@Jurigag
Copy link
Contributor

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 commented Feb 19, 2017

+1

@dictbox
Copy link

dictbox commented Feb 19, 2017

Laravel support similar function。

@stale
Copy link

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 Stale issue - automatically closed label Apr 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stale Stale issue - automatically closed
Projects
None yet
Development

No branches or pull requests