Skip to content

Commit

Permalink
Update 15_Update.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Renyu106 authored Nov 15, 2023
1 parent 58f6510 commit ce7f5da
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions docs/10__SQL_Query_Builder/15_Update.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
# SQL Update
# SQL ์—…๋ฐ์ดํŠธ

Updating data follows very similar rules as the select. At least when it comes to query building.
๋ฐ์ดํ„ฐ ์—…๋ฐ์ดํŠธ๋Š” ์ฟผ๋ฆฌ ๊ตฌ์ถ• ์ธก๋ฉด์—์„œ `SELECT`์™€ ๋งค์šฐ ์œ ์‚ฌํ•œ ๊ทœ์น™์„ ๋”ฐ๋ฅด๊ณ ์žˆ์Šต๋‹ˆ๋‹ค

> Note: The displayed SQL query in the examples has no prepared statements. In other words the "?" placeholders have been replaced with the actual parameter.
> ์ฐธ๊ณ : ์˜ˆ์‹œ์— ํ‘œ์‹œ๋œ SQL ์ฟผ๋ฆฌ์—๋Š” ์ค€๋น„๋œ ๋ฌธ์žฅ์ด ์—†์Šต๋‹ˆ๋‹ค. ์ฆ‰, "?" ํ”Œ๋ ˆ์ด์Šคํ™€๋”๊ฐ€ ์‹ค์ œ ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ๋Œ€์ฒด๋˜์—ˆ์Šต๋‹ˆ๋‹ค
##ย Basic update
## ๊ธฐ๋ณธ ์—…๋ฐ์ดํŠธ

```php
// SQL: update `users` set `active` = 0
$h->table('users')->update(['active' => 0])->execute();
```
์—…๋ฐ์ดํŠธ ์ฟผ๋ฆฌ ๋นŒ๋”๋Š” `SELECT` ๊ธฐ๋ณธ์„ ํ™•์žฅํ•˜์—ฌ ๋ชจ๋“  `where` ๋ฐ `limit` ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ฉ๋‹ˆ๋‹ค

The update query builder extends the select base, allowing you to make use of all `where` and `limit` methods.

So because you probably don't want to set all your user's inactive start some filtering.
์ผ๋ถ€ ๋ฐ์ดํ„ฐ๋งŒ ๋ณ€๊ฒฝํ• ๋ ค๋ฉด `where`๊ฐ™์€ ์กฐ๊ฑด๋ฌธ์„ ์‚ฌ์šฉํ•˜์—ฌ ํ•„ํ„ฐ๋ง์„ ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค

```php
// SQL: update `users` set `active` = 0 where `last_login` < '2015-01-01'
Expand All @@ -23,13 +22,10 @@ $h->table('users')
->execute();

```
`UPDATE` ๋ฉ”์†Œ๋“œ์— ์ „๋‹ฌ๋˜๋Š” ์ธ์ž๋Š” `set` ๋ฉ”์†Œ๋“œ๋กœ ์ „๋‹ฌ๋ฉ๋‹ˆ๋‹ค

The argument that the `update` methods takes in will be forwarded to the `set` method.

[~ PHPDoc](/src/Query/Sql/Update.php#set)

The set method can be used in a key-value manner.

`set` ๋ฉ”์†Œ๋“œ๋Š” Key(Column) - Value ๋ฐฉ์‹์œผ๋กœ ์‚ฌ์šฉ๋  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค
```php
// SQL: update `users` set `name` = Arthur, `follower_count` = 42 where `id` = 12
$h->table('users')->update()
Expand All @@ -39,12 +35,12 @@ $h->table('users')->update()
->execute();
```

Or you might also pass in an array.

๋˜๋Š” ๋ฐฐ์—ดํ˜•ํƒœ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค
๋ฐฐ์—ดํ˜•ํƒœ๋กœ ์ „๋‹ฌํ•ด๋„ Key(Column) - Value ํ˜•ํƒœ๋Š” ๋˜‘๊ฐ™์Šต๋‹ˆ๋‹ค
```php
// SQL: update `users` set `name` = Arthur, `follower_count` = 42 where `id` = 12
$h->table('users')->update()
->set(['name' => 'Arthur', 'follower_count' => 42)
->set(['name' => 'Arthur', 'follower_count' => 42])
->where('id', 12)
->execute();
```

0 comments on commit ce7f5da

Please sign in to comment.