Skip to content

Commit

Permalink
新增支持配置数据库名
Browse files Browse the repository at this point in the history
  • Loading branch information
Yurunsoft committed Dec 21, 2021
1 parent cd7d5d8 commit 2ec5d3e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
// 'port' => 6041,
// 'user' => 'root',
// 'password' => 'taosdata',
// 'db' => 'database'
// 'ssl' => false,
// 'timestampFormat' => \Yurun\TDEngine\Constants\TimeStampFormat::LOCAL_STRING,
// 'keepAlive' => true,
Expand All @@ -52,6 +53,7 @@ $client = new \Yurun\TDEngine\Client(new \Yurun\TDEngine\ClientConfig([
// 'port' => 6041,
// 'user' => 'root',
// 'password' => 'taosdata',
// 'db' => 'database'
// 'ssl' => false,
// 'timestampFormat' => \Yurun\TDEngine\Constants\TimeStampFormat::LOCAL_STRING,
// 'keepAlive' => true,
Expand Down
5 changes: 5 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ public function sql(string $sql): SqlResult
default:
throw new InvalidArgumentException(sprintf('Invalid timestampFormat %s', $config->getTimestampFormat()));
}
$db = $config->getDb();
if ('' !== $db)
{
$path .= '/' . $db;
}
$result = $this->request($path, $sql);

return new SqlResult($result);
Expand Down
17 changes: 17 additions & 0 deletions src/ClientConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ class ClientConfig
*/
protected $password = 'taosdata';

/**
* @var string
*/
protected $db = '';

/**
* @var bool
*/
Expand Down Expand Up @@ -119,6 +124,18 @@ public function setPassword(string $password): self
return $this;
}

public function getDb(): string
{
return $this->db;
}

public function setDb(string $db): self
{
$this->db = $db;

return $this;
}

public function getSsl(): bool
{
return $this->ssl;
Expand Down

0 comments on commit 2ec5d3e

Please sign in to comment.