sad-spirit / pg-wrapper Goto Github PK
View Code? Open in Web Editor NEWConverter of complex PostgreSQL types and an OO wrapper for PHP's pgsql extension
License: BSD 2-Clause "Simplified" License
Converter of complex PostgreSQL types and an OO wrapper for PHP's pgsql extension
License: BSD 2-Clause "Simplified" License
Transaction
object, Connection::begin()
will return an instance of that.Transaction
will have at least commit()
, rollback()
and savepoint()
methodsMaybe it is a good idea to behave like python's sqlalchemy and keep count of how many times begin()
was called and actually commit when commit()
was called that many times as well:
https://docs.sqlalchemy.org/en/13/core/connections.html#using-transactions
Specifically, ArrayConverter
, CompositeConverter
and RangeConverter
. Their subtype can be one of the date / time types that are affected by DateStyle
database setting, so connection should be accepted and propagated to ConnectionAware
subtypes.
InvalidQueryException
should probably be renamed to DatabaseException
: current name is misleading as the query may be perfectly valid but failing for whatever reason. It may be a good idea to follow Doctrine DBAL by providing specialized subclasses of DatabaseException
and create them based on SQLSTATE field.
Need to check what is being returned by pg_last_error()
if connection to the DB is lost and throw ConnectionException
in that case.
The methods are too liberal to throw InvalidArgumentException
for all kinds of errors, some of which are essentially runtime, e.g. in ResultSet
offsetSet()
and offsetUnset()
should probably throw an instance of BadMethodCallException
checkFieldIndex()
should probably throw an instance of OutOfBoundsException
for missing field index / name (fetchAll()
probably too)in PreparedStatement
bindValue()
and bindParam()
should throw an instance of OutOfRangeException
(we can't check that the value is within the count of actual placeholders, but we can at least check that it is >= 1)
in DefaultTypeConverterFactory
[improved, see #7] method getConverterForTypeOid()
should probably never throw exceptions at all while getConverterForTypeSpecification()
should throw a specialized subclass of InvalidArgumentException
for missing converters.
Up the dependency in composer.json
Change .travis.yml
to test on PHP 7.2+ only
Drop version checks in code (e.g. JSONTest::testJSONBigintAsString()
) and workarounds (e.g. in JSONConverter
)
As I targeted PEAR coding standards (without anal PHPDoc) there isn't much to do, mostly
switch
constructsOne idiotic problem with that CS is that blank line is not allowed before else / elseif:
if (is_numeric($native)) {
return $native;
} elseif (0 === strcasecmp($native, 'NaN')) {
return NAN;
} else {
throw TypeConversionException::unexpectedValue($this, 'input', 'numeric value', $native);
}
results in
ERROR | [x] Blank line found at end of control structure
Need to think of the options here.
Setting deprecated in PHP 7.2 and will be removed in PHP 8
This should give a speedup for type converters by removing unneeded indirections via call_user_func()
...into several methods:
getConverterForTypeOid()
- this one will not work without connection and will not throw an exception if a specific converter cannot be found, returning something like StubConverter
instead.getConverterForTypeSpecification()
- this one will throw exceptions if a specific converter is not foundexecute()
and friends.Also it may be a good idea to add
getConverterForValue()
- similar to what Connection::guessOutput()
currently does but with a means to register the specific class to look for. E.g. registerConverter()
registers IntervalConverter
and the fact that it would like to convert all instances of DateInterval
by default.guessOutput()
knows too much about implementation details and will not work correctly with StubConverterFactory
currently. Needs to be removed.
In another words, drop empty directories from src/
and update composer.json
Hi, thanks for your library it's really helping.
i have a question, i want to json_encode a Point but i was getting an empty array, is there any other way then to set my own PointConverter and Point type. Thanks.
This one is obvious.
Drop version checks in code (e.g. in ByteaConverter
and `DefaultTypeConverterFactory::_loadTypes())
Probably throw an Exception in Connection::connect()
if server version is below 9.2 (we don't actually depend on features of later versions)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.