forked from rmunate/SQLServerLite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
cgrodriguez0073
committed
Dec 11, 2023
1 parent
7620ea2
commit 42bafc3
Showing
5 changed files
with
181 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--- | ||
title: Numbers To Money | ||
editLink: true | ||
outline: deep | ||
--- | ||
|
||
# Connections | ||
|
||
### Connection | ||
|
||
You can establish a connection to the SQL Server database using the credentials set in the config/database.php file. | ||
|
||
```php | ||
'sqlsrv' => [ | ||
'driver' => 'sqlsrv', | ||
'url' => env('DATABASE_URL'), | ||
'host' => env('DB_HOST', 'localhost'), | ||
'database' => env('DB_DATABASE', 'forge'), | ||
'username' => env('DB_USERNAME', 'forge'), | ||
'password' => env('DB_PASSWORD', ''), | ||
] | ||
``` | ||
|
||
### Extended Connection | ||
|
||
The above configuration includes the mandatory data for the connection. If additional parameters, such as a port, are required, you can extend the configuration as follows: | ||
|
||
```php | ||
'sqlsrv' => [ | ||
'driver' => 'sqlsrv', | ||
'url' => env('DATABASE_URL'), | ||
'instance' => env('DB_INSTANCE'), | ||
'host' => env('DB_HOST', 'localhost'), | ||
'port' => env('DB_PORT', '1433'), | ||
'database' => env('DB_DATABASE', 'forge'), | ||
'username' => env('DB_USERNAME', 'forge'), | ||
'password' => env('DB_PASSWORD', ''), | ||
'charset' => 'utf8', | ||
] | ||
``` | ||
|
||
These configurations provide the necessary information for both basic and extended SQL Server connections. | ||
|
||
After configuring the settings, you can establish the connection using the connection method | ||
|
||
```php | ||
use Rmunate\SqlServerLite\SQLServer; | ||
|
||
SQLServer::connection('sqlsrv'); | ||
|
||
``` | ||
|
||
### Status | ||
|
||
The library provides a status method to check the connection status. You can define a custom timeout or use the default timeout (3). | ||
|
||
```php | ||
use Rmunate\SqlServerLite\SQLServer; | ||
|
||
SQLServer::status('sqlsrv')->isConnected(); | ||
// true if connected successfully | ||
|
||
``` | ||
|
||
The isConnected method is recommended, as it returns true if the connection is successful. | ||
|
||
|
||
This allows you to easily verify the status of the SQL Server connection and obtain relevant information. | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
--- | ||
title: SQLServer Methods | ||
editLink: true | ||
outline: deep | ||
--- | ||
|
||
# Methods | ||
|
||
## SELECT | ||
|
||
### GET | ||
|
||
You can quickly execute a SELECT query in the database by sending it directly and return a collection. | ||
|
||
```php | ||
use Rmunate\SqlServerLite\SQLServer; | ||
|
||
$query = SQLServer::connection('sqlsrv')->select('SELECT * FROM cities'); | ||
//prepare the query | ||
$query->get(); | ||
``` | ||
|
||
### FIRST | ||
|
||
You can also use the 'first' method to retrieve the initial object in the collection. | ||
|
||
```php | ||
use Rmunate\Utilities\SQLServer; | ||
|
||
$query = SQLServer::connection('sqlsrv')->select('SELECT * FROM cities'); | ||
//prepare the query | ||
$query->get()->first(); | ||
``` | ||
|
||
### orderBy | ||
|
||
You can also use the 'orderBy' method to fetch a collection ordered in ascending (asc) order. | ||
|
||
```php | ||
use Rmunate\Utilities\SQLServer; | ||
|
||
$query = SQLServer::connection('sqlsrv')->select('SELECT * FROM cities'); | ||
//prepare the query | ||
|
||
$query->orderBy('asc')->get(); | ||
|
||
``` | ||
|
||
### COUNT | ||
|
||
The 'count' method can be used to retrieve the total count of the collection. | ||
|
||
```php | ||
use Rmunate\Utilities\SQLServer; | ||
|
||
$query = SQLServer::connection('sqlsrv')->select('SELECT * FROM cities'); | ||
//prepare the query | ||
|
||
$query->get()->count(); | ||
|
||
``` | ||
|
||
### PLUCK | ||
|
||
The 'pluck' method returns an array with the specified column and an optional index. | ||
|
||
```php | ||
use Rmunate\Utilities\SQLServer; | ||
|
||
$query = SQLServer::connection('sqlsrv')->select('SELECT * FROM cities'); | ||
//prepare the query | ||
|
||
$query->pluck('name', 'index'); | ||
//Return an array with the column and an optional index. | ||
``` | ||
|
||
### CHUNK | ||
|
||
The chunk method proves useful when dealing with thousands of database records. It retrieves results in small chunks, processing each one within a closure. | ||
|
||
```php | ||
use Rmunate\Utilities\SQLServer; | ||
|
||
$query = SQLServer::connection('sqlsrv')->select('SELECT * FROM cities'); | ||
//prepare the query | ||
|
||
$query->chunk(100, function (Collection $users) { | ||
foreach ($users as $user) { | ||
// ... | ||
} | ||
}); | ||
``` | ||
|
||
### ALL | ||
|
||
$query->all(); | ||
//Return the collection as with the 'get' method. | ||
$query->value('name'); | ||
//Return the value of a specific column.. | ||
$query->get()->last(); | ||
//Return the last object. | ||
|
||
$query->value('name')->each(function (object $user) { | ||
// ... | ||
}); | ||
// Works similarly to the `chunk` method but returns a LazyCollection. | ||
|
||
$query->max('name'); | ||
//Return the value of a specific column.. | ||
|