Skip to content

Query Builder

Mehedi Hasan edited this page Apr 9, 2022 · 2 revisions

Database: Query Builder

Retrieving All Rows From A Table

You may use the table method provided by the DB facade to begin a query. The table method returns a fluent query builder instance for the given table, allowing you to chain more constraints onto the query and then finally retrieve the results of the query using the scan or query method:

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;

class UserController extends Controller
{
    /**
     * Show a list of all of the application's users.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        // Scan operation
        $users = DB::table('users')->scan();
        
        // Query Operation
        $users = DB::table('users')->keyCondtion('PK', 'USERS')->query();

        return view('user.index', ['users' => $users]);
    }
}

Consistent Read

Determines the read consistency model: If set to true, then the operation uses strongly consistent reads; otherwise, the operation uses eventually consistent reads.

Strongly consistent reads are not supported on global secondary indexes. If you query a global secondary index with ConsistentRead set to true, you will receive a ValidationException.

Type: Boolean

DB::table('users')->consistentRead(true)->keyCondition('PK', 'USERS')->query();

From, Table

The name of the table containing the requested items.

// Scanning items from a table
$users = DB::from('users')->scan();

// Query items from a table using DynamoDB Query API
$users = DB::table('users')->keyCondition('PK', 'USERS')->query();
Clone this wiki locally