Skip to content

Commit 888ada5

Browse files
committed
feat: add methods for namespace, tenant, and shared tables support in Adapter and Database classes
1 parent 0eb17a1 commit 888ada5

3 files changed

Lines changed: 100 additions & 0 deletions

File tree

src/Usage/Adapter.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,28 @@ abstract public function find(array $queries = []): array;
9494
* @return int
9595
*/
9696
abstract public function count(array $queries = []): int;
97+
98+
/**
99+
* Set the namespace prefix for table names.
100+
*
101+
* @param string $namespace
102+
* @return self
103+
*/
104+
abstract public function setNamespace(string $namespace): self;
105+
106+
/**
107+
* Set the tenant ID for multi-tenant support.
108+
*
109+
* @param int|null $tenant
110+
* @return self
111+
*/
112+
abstract public function setTenant(?int $tenant): self;
113+
114+
/**
115+
* Enable or disable shared tables mode (multi-tenant with tenant column).
116+
*
117+
* @param bool $sharedTables
118+
* @return self
119+
*/
120+
abstract public function setSharedTables(bool $sharedTables): self;
97121
}

src/Usage/Adapter/Database.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,4 +445,43 @@ public function count(array $queries = []): int
445445

446446
return $count;
447447
}
448+
449+
/**
450+
* Set the namespace prefix for table names.
451+
* (Not supported in Database adapter)
452+
*
453+
* @param string $namespace
454+
* @return self
455+
*/
456+
public function setNamespace(string $namespace): self
457+
{
458+
$this->db->setNamespace($namespace);
459+
return $this;
460+
}
461+
462+
/**
463+
* Set the tenant ID for multi-tenant support.
464+
* (Not supported in Database adapter)
465+
*
466+
* @param int|null $tenant
467+
* @return self
468+
*/
469+
public function setTenant(?int $tenant): self
470+
{
471+
$this->db->setTenant($tenant);
472+
return $this;
473+
}
474+
475+
/**
476+
* Enable or disable shared tables mode (multi-tenant with tenant column).
477+
* (Not supported in Database adapter)
478+
*
479+
* @param bool $sharedTables
480+
* @return self
481+
*/
482+
public function setSharedTables(bool $sharedTables): self
483+
{
484+
$this->setSharedTables($sharedTables);
485+
return $this;
486+
}
448487
}

src/Usage/Usage.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,41 @@ public function count(array $queries = []): int
183183
{
184184
return $this->adapter->count($queries);
185185
}
186+
187+
/**
188+
* Set the namespace prefix for table names.
189+
*
190+
* @param string $namespace
191+
* @return $this
192+
* @throws \Exception
193+
*/
194+
public function setNamespace(string $namespace): self
195+
{
196+
$this->adapter->setNamespace($namespace);
197+
return $this;
198+
}
199+
200+
/**
201+
* Set the tenant ID for multi-tenant support.
202+
*
203+
* @param int|null $tenant
204+
* @return $this
205+
*/
206+
public function setTenant(?int $tenant): self
207+
{
208+
$this->adapter->setTenant($tenant);
209+
return $this;
210+
}
211+
212+
/**
213+
* Enable or disable shared tables mode (multi-tenant with tenant column).
214+
*
215+
* @param bool $sharedTables
216+
* @return $this
217+
*/
218+
public function setSharedTables(bool $sharedTables): self
219+
{
220+
$this->adapter->setSharedTables($sharedTables);
221+
return $this;
222+
}
186223
}

0 commit comments

Comments
 (0)