Skip to content

Commit

Permalink
add float type; needs test; closes #5
Browse files Browse the repository at this point in the history
  • Loading branch information
Rasmus Schultz committed May 23, 2016
1 parent 7d0a28b commit 4715406
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/model/types/FloatType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace mindplay\sql\model\types;

use mindplay\sql\model\schema\Type;

class FloatType implements Type
{
public function convertToSQL($value)
{
return $value === null
? null
: (string) $value;
}

public function convertToPHP($value)
{
return $value === null
? null
: (float) $value;
}
}
3 changes: 3 additions & 0 deletions src/mysql/MySQLDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use mindplay\sql\model\query\UpdateQuery;
use mindplay\sql\model\schema\Table;
use mindplay\sql\model\types\BoolType;
use mindplay\sql\model\types\FloatType;

class MySQLDatabase extends Database
{
Expand All @@ -21,6 +22,8 @@ public function __construct()
});

$this->container->alias("scalar.boolean", BoolType::class);

$this->container->register("scalar.double", FloatType::class);
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/postgres/PostgresDatabase.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use mindplay\sql\model\Database;
use mindplay\sql\model\schema\Table;
use mindplay\sql\model\types\BoolType;
use mindplay\sql\model\types\FloatType;

class PostgresDatabase extends Database
{
Expand All @@ -17,6 +18,8 @@ public function __construct()
});

$this->container->alias("scalar.boolean", BoolType::class);

$this->container->register("scalar.double", FloatType::class);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions test/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1440,6 +1440,8 @@ function () {

// TODO integration test for driver-generated SQLException-types

// TODO add test for FloatType

configure()->enableCodeCoverage(__DIR__ . '/build/clover.xml', dirname(__DIR__) . '/src');

exit(run());

0 comments on commit 4715406

Please sign in to comment.