diff --git a/README.md b/README.md index 696ff70..b2de1ae 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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.