> For the complete documentation index, see [llms.txt](https://ronaldaug.gitbook.io/sim-rest/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ronaldaug.gitbook.io/sim-rest/database/db-query.md).

# DB Query

## GET collection

Example of getting the whole **posts** collection

```php
DB::table('posts')->all();
```

Example of getting a single collection by **\_id**

\_id | **String**

```php
DB::table('posts')->where('_id',$id)->get();
```

Example of getting a single collection by **key and value**

key | **String**\
value | **String**

```php
DB::table('posts')->where('key',$value)->get();
```

## ADD collection

Example of adding a new **post** collection

$request\_data | **Array**

```php
DB::where('posts')->save($request_data);
```

## UPDATE collection

Example of updating a collection.&#x20;

This usually use with **$router->put()** method

$request\_data | **Array**

Note -  $request\_data must include `_id` field

```php
DB::where('posts')->save($request_data); 
```

## DELETE collection

Example of deleting a collection

$id | **String**

```php
DB::where('posts')->delete($id); 
```

##
