diff --git a/app/Model/Job.php b/app/Model/Job.php index b1bf6e6..27e0a4e 100644 --- a/app/Model/Job.php +++ b/app/Model/Job.php @@ -9,7 +9,7 @@ use Fufle\ORM\Model as BaseModel; class Job extends BaseModel { public int $id; public float $budget; - public static function QueryModel() { + public static function SetQueryModel() { return new JobQuery( static::class ); } diff --git a/app/Query/JobQuery.php b/app/Query/JobQuery.php index 8f064e9..9f9df4c 100644 --- a/app/Query/JobQuery.php +++ b/app/Query/JobQuery.php @@ -7,6 +7,6 @@ use Fufle\ORM\Query as BaseQuery; class JobQuery extends BaseQuery implements IJobQuery { public function GetLast10(): string { - return "select * from jobs order by id desc limit 10"; + return "SELECT * from jobs order by id desc limit 10"; } } diff --git a/src/Fufle/Database/ConnectionManager.php b/src/Fufle/Database/ConnectionManager.php deleted file mode 100644 index d1e4ecb..0000000 --- a/src/Fufle/Database/ConnectionManager.php +++ /dev/null @@ -1,32 +0,0 @@ -normalize(); - $stmt = self::$connection->prepare($data->query); - $stmt->execute($data->params); - $stmt->setFetchMode(PDO::FETCH_CLASS, $output); - return $stmt->fetch(); - } - - public static function QueryAll(string $query, array|object $params = [], string $output = 'stdObject') { - $data = new QueryData($query, $params); - $data->normalize(); - $stmt = self::$connection->prepare($data->query); - $stmt->execute($data->params); - $stmt->setFetchMode(PDO::FETCH_CLASS, $output); - return $stmt->fetchAll(); - } -} \ No newline at end of file diff --git a/src/Fufle/Database/Connector/IConnector.php b/src/Fufle/Database/Connector/IConnector.php deleted file mode 100644 index e69de29..0000000 diff --git a/src/Fufle/Database/Connector/PostgresConnector.php b/src/Fufle/Database/Connector/PostgresConnector.php deleted file mode 100644 index e69de29..0000000 diff --git a/src/Fufle/ORM/Database/ConnectionManager.php b/src/Fufle/ORM/Database/ConnectionManager.php new file mode 100644 index 0000000..54935ef --- /dev/null +++ b/src/Fufle/ORM/Database/ConnectionManager.php @@ -0,0 +1,52 @@ +driverEquals($driver)) { + $credentials = new Credentials($host, $port, $database, $user, $password); + self::$connectionString = $c->getConnectionString($credentials); + self::ConnectWithString(self::$connectionString); + return; + } + } + throw new Exception('Driver not found'); + } + + public static function ConnectWithString(string $connectionString) { + self::$connection = new PDO($connectionString); + } + + public static function Query(string $query, array|object $params = [], string $output = 'stdObject') { + $data = new QueryData($query, $params); + $data->normalize(); + $stmt = self::$connection->prepare($data->query); + $stmt->execute($data->params); + $stmt->setFetchMode(PDO::FETCH_CLASS, $output); + return $stmt->fetch(); + } + + public static function QueryAll(string $query, array|object $params = [], string $output = 'stdObject') { + $data = new QueryData($query, $params); + $data->normalize(); + $stmt = self::$connection->prepare($data->query); + $stmt->execute($data->params); + $stmt->setFetchMode(PDO::FETCH_CLASS, $output); + return $stmt->fetchAll(); + } +} \ No newline at end of file diff --git a/src/Fufle/ORM/Database/Connector/IConnector.php b/src/Fufle/ORM/Database/Connector/IConnector.php new file mode 100644 index 0000000..0fac25d --- /dev/null +++ b/src/Fufle/ORM/Database/Connector/IConnector.php @@ -0,0 +1,9 @@ +