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

Version 1.0.8 doc updates #20

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file. This project adhere to the [Semantic Versioning](http://semver.org/) standard.

## [1.0.8] TBD
## [1.0.8] 2024-02-23

* Feat - Add the `DB::generate_results` and `DB::generate_col` methods to the `DB` class to fetch all results matching an unbounded query with a set of bounded queries.

Expand Down
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ composer require stellarwp/db
- [Inherited from `$wpdb`](#inherited-from-wpdb)
- [`get_var()`](#get_var)
- [`get_col()`](#get_col)
- [`generate_col()`](#get_col)
- [`get_results()`](#get_results)
- [`generate_results()`](#generate_results)
- [`esc_like()`](#esc_like)
- [`remove_placeholder_escape()`](#remove_placeholder_escape)

Expand Down Expand Up @@ -930,6 +933,55 @@ $meta_values = DB::get_col(
);
```

### `generate_col()`

Returns a Generator that will produce an array of values for the column for the given query.
Differrently from the `get_col()` method, this method will run unbounded queries (queries without a `LIMIT` set) in batches, ensuring as-efficient-as-possible use of the database and memory.

```php
$meta_values = DB::generate_col(
DB::table( 'postmeta' )
->select( 'meta_value' )
->where( 'meta_key', 'some_key' )
->getSQL()
);

foreach( $meta_values as $meta_value ) {
// Do something with the meta value.
}
```

### `get_results()`

Returns an array of rows for for the given query.

```php
$private_posts = DB::get_results(
DB::table( 'posts' )
->select( '*' )
->where( 'post_status', 'private' )
->getSQL()
);
```

### `generate_results()`

Returns a Generator that will produce an array of rows for the given query.
Differrently from the `get_results()` method, this method will run unbounded queries (queries without a `LIMIT` set) in batches, ensuring as-efficient-as-possible use of the database and memory.

```php
$private_posts = DB::generate_results(
DB::table( 'posts' )
->select( '*' )
->where( 'post_status', 'private' )
->getSQL()
);

foreach( $private_posts as $private_post ) {
// Do something with the post.
}
```

### `esc_like()`

Escapes a string with a percent sign in it so it can be safely used with [Where LIKE](#where-like-clauses) without the percent sign being interpreted as a wildcard character.
Expand Down
Loading