π Usage β
Connecting to a Database β
By default, Sparkle will use the default database connection. You can switch to a different connection using the connection() method:
php
use Sirmerdas\Sparkle\Database\Sparkle;
Sparkle::connection(string $connectionName): self
// Switch to a different database connection
Sparkle::connection('sparkle');WARNING
Note: Changing the connection affects the entire application globally.
Querying a Table β
You can create a query builder instance for a specific table using the table() method. This method returns a new instance of Builder (Sirmerdas\Sparkle\Database\QueryBuilder\Builder):
php
use Sirmerdas\Sparkle\Database\Sparkle;
Sparkle::table(string $table, string|null $as = null): Builder
// Example usage on orders table:
Sparkle::table('orders');Using a Different Connection for a Query β
If you need to use a different connection for a specific query, you can chain connection() and table() together:
php
use Sirmerdas\Sparkle\Database\Sparkle;
// Use a specific connection and query the 'users' table
Sparkle::connection('sparkle')::table('users');π Important Notes β
- Global Connection Change: When you change the database connection using
Sparkle::connection(), it changes the connection for the entire application. - Fluent Interface: The API is designed to be chainable for better readability.