Skip to content

Commit

Permalink
ajuste solicitudes
Browse files Browse the repository at this point in the history
  • Loading branch information
cgrodriguez0073 committed Dec 11, 2023
1 parent 7620ea2 commit 42bafc3
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 184 deletions.
4 changes: 2 additions & 2 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export default defineConfig({
text: 'Usage',
collapsed: false,
items: [
{text: 'Numbers To Letters', link: '/usage/numbers-to-letters'},
{text: 'Numbers To Money', link: '/usage/numbers-to-money'},
{text: 'Connection', link: '/usage/connection'},
{text: 'Query Methods', link: '/usage/query-methods'},
{text: 'Numbers To Ordinal', link: '/usage/numbers-to-ordinal'},
{text: 'Config File', link: '/usage/config-file'},
{text: 'Config Custom Callback', link: '/usage/config-custom-callback'},
Expand Down
69 changes: 69 additions & 0 deletions docs/usage/connection.md
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.

92 changes: 0 additions & 92 deletions docs/usage/numbers-to-letters.md

This file was deleted.

90 changes: 0 additions & 90 deletions docs/usage/numbers-to-money.md

This file was deleted.

110 changes: 110 additions & 0 deletions docs/usage/query-methods.md
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..

0 comments on commit 42bafc3

Please sign in to comment.