Skip to content

Commit 65314dc

Browse files
committed
Add cached granulation of tables and more explicit variable names
1 parent 2c51bdf commit 65314dc

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,9 @@ return [
5757
'database' => env('DB_DATABASE', 'mydatabase'),
5858
'username' => env('DB_USERNAME', 'user'),
5959
'password' => env('DB_PASSWORD', 'password'),
60-
'charset' => 'utf8', // Experimental yet, prefer use the `DB_CHARSET` and `APPLICATION_CHARSET`
60+
'charset' => 'utf8',
6161
'prefix' => '',
62+
'cache' => true // By default it caches on all connections, if you want some connection not remembered assign `false` (Recommended when modification is performed on tables frequently [development])
6263
],
6364

6465
...
@@ -96,19 +97,19 @@ The file is usualy found in **/etc/freetds/freetds.conf**. Set the configuration
9697
```
9798

9899
## Configuring the charset between the database and the application
99-
To configure the charset between the database and the application, add the fields `DB_CHARSET` and `APPLICATION_CHARSET` in `.env` file, see the following example:
100+
To configure the charset between the database and the application, add the fields `DATABASE_CHARSET` and `APPLICATION_CHARSET` in `.env` file, see the following example:
100101

101102
```env
102-
DB_CHARSET=CP850
103+
DATABASE_CHARSET=CP850
103104
APPLICATION_CHARSET=UTF8
104105
```
105106
## Configuring the cache
106107
As the library consults table information whenever it receives a request, caching can be used to avoid excessive queries
107108

108-
To use the cache, add the fields `SYBASE_CACHE_COLUMNS` and `SYBASE_CACHE_COLUMNS_TIME` to the `.env` file, see the following example:
109+
To use the cache, add the fields `SYBASE_CACHE_TABLES` and `SYBASE_CACHE_TABLES_TIME` to the `.env` file, see the following example:
109110
```dotenv
110-
SYBASE_CACHE_COLUMNS=true
111-
SYBASE_CACHE_COLUMNS_TIME=3600 # cache table information by `3600` seconds
111+
SYBASE_CACHE_TABLES=true
112+
SYBASE_CACHE_TABLES_TIME=3600 # cache table information by `3600` seconds
112113
```
113114

114115
## Setting to use numeric data type

src/Database/Connection.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ private function compile(Builder $builder)
147147
}
148148
}
149149

150-
$cache_columns = env('SYBASE_CACHE_COLUMNS');
150+
$cache_tables = env('SYBASE_CACHE_TABLES');
151+
$cache = !key_exists('cache_tables', $builder->connection->config) || $builder->connection->config['cache_tables'];
152+
151153
$types = [];
152154

153155
foreach ($arrTables as $tables) {
@@ -163,8 +165,8 @@ private function compile(Builder $builder)
163165
$tables = $alias['table'];
164166
}
165167

166-
if($cache_columns == true) {
167-
$aux = Cache::remember('sybase_columns/'.$tables.'.columns_info', env('SYBASE_CACHE_COLUMNS_TIME') ?? 600, function() use($tables) {
168+
if($cache_tables && $cache) {
169+
$aux = Cache::remember('sybase_columns/'.$tables.'.columns_info', env('SYBASE_CACHE_TABLES_TIME') ?? 3600, function() use($tables) {
168170
$queryString = $this->queryString($tables);
169171
$queryRes = $this->getPdo()->query($queryString);
170172
return $queryRes->fetchAll(PDO::FETCH_NAMED);
@@ -359,7 +361,7 @@ private function compileNewQuery($query, $bindings)
359361
$newQuery = join(array_map(fn($k1, $k2) => $k1.$k2, $partQuery, $bindings));
360362
$newQuery = str_replace('[]', '', $newQuery);
361363

362-
$db_charset = env('DB_CHARSET');
364+
$db_charset = env('DATABASE_CHARSET');
363365
$app_charset = env('APPLICATION_CHARSET');
364366

365367
if($db_charset && $app_charset) {
@@ -395,7 +397,7 @@ public function select($query, $bindings = [], $useReadPdo = true)
395397

396398
$result = $statement->fetchAll($this->getFetchMode());
397399

398-
$db_charset = env('DB_CHARSET');
400+
$db_charset = env('DATABASE_CHARSET');
399401
$app_charset = env('APPLICATION_CHARSET');
400402

401403
if($db_charset && $app_charset) {

0 commit comments

Comments
 (0)