Giter VIP home page Giter VIP logo

postgres.py's People

Contributors

brien-givens avatar chadwhitacre avatar changaco avatar clivern avatar rohitpaulk avatar techtonik avatar tshepang avatar zwn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

postgres.py's Issues

lazy-load foreign keys

It'd be nice to have a built-in API for lazily loading foreign records. See #22 for a pre-loading implementation.

link to parent for nested types?

I have a column of a custom type, and I want a reference to the parent for the child. I want to be able to do:

foo = Participant.from_username('foo')
foo.email.send(message)

... and inside send have access to foo.username, etc.

add a one_or_zero method

Often you are fine with zero or one result but more than one would indicate a bug. Right now you can do:

try:
    rec = db.one(QUERY)
except TooFew:
    rec = None

if rec is None:
    pass
else:
    pass

But it might be nicer to be able to do:

rec = db.one_or_zero(QUERY)
if rec is None:
    pass
else:
    pass

ORM register_model does not work outside of "public" schema

if I have a table in a schema other than public, Psycopg2 will check for the form 'schema.type' but postgres.py does not, so a model with typname 'type' will pass:
631 n = self.one( "SELECT count(*) FROM pg_type WHERE typname=%s"
632 , (typname,)
633 )
but it will fail in psycopg2.extras because of missing schema name.

eliminate race condition when updating types

We ran into an issue over on gratipay/gratipay.com#1583 in that psycopg2 caches information about composite types, so if you alter the type in the database then the cache becomes stale, and the next time you request a record of the composite type, you get a DataError. From @dvarrazzo:

The composite cache is local to where register_composite was called (globally, the connection, or the cursor). You can avoid the problem using it in a restricted scope (e.g. on a cursor, and dropping the cursor after the type is changed). Alternatively just rerun register_composite with the same arguments after changing the type.

And over on http://psycopg.lighthouseapp.com/projects/62710/tickets/183:

Caching of the attribute is necessary but it's local to the scope you have registered the composite.
Avoid using register_composite with global=True: use it on the connection or on the cursor, and dispose the connection or the cursor after the data type is changed. Alternatively just call register_composite again.

How do we eliminate this race condition?

rename rows to all

Our simple API: run / one / rows

one and rows aren't parallel. :-(

We should either change one to row or rows to many. I like row better because it keeps the aliteration and one and many feel ORM-ish to me.

Since we've already released 1.0.0 we've got a backwards-compatibility issue. Since we're so early in the project (I released 1.0.0 about 8 or 9 hours ago), I think we can get away with aliasing row as one but not documenting it.

conform to Records' API

@kennethreitz has launched Records, "SQL for Humans™". Given the relative star count (~1,500 in 6 days vs. 36 in 3 years), it seems that the Python world now has a de facto DB-API 3.0—and it's not ours. :o)

Records is database-agnostic (cf. kennethreitz/records#41). So far it seems to me that there's value in continuing with Postgres.py because of the ORM layer. The proposal here is to change our top-level run/one/all API to conform to what @kennethreitz has come up with:

row_iterator = db.query('select * from foo')
row_list = row_iterator.all()

So we'd essentially rename run to query, and chain all (and one, which Records doesn't have—yet?) onto the result.

rename get_cursor to Cursor, etc.

with db.get_cursor(SQL) as cursor:
    pass

The get_ there is clunky. Let's name these like constructors:

with db.Cursor(SQL) as cursor:
    pass

set up travis

Eventually we need a test matrix with multiple versions of Python, psycopg2, and PostgreSQL. Let's start with one cell.

change from CC0 to MIT

CC0 is problematic outside the U.S. SQLite solves the problem by charging people who care $1,000. We should just drop back to MIT for path of least resistance.

Safe interpolation of column names

Why don't we have this? It seems to me that a column name can be checked with a simple regexp, and a placeholder different than %s (e.g. %c) could be used to insert a column name into a query.

This is probably more of a psycopg2 issue, but let's discuss it here first, especially since we're considering porting to asyncpg (#58).

set-up PyPI classifiers

I am mostly interested in the info that this can actually run on Python 3.

I would submit a patch, but I don't know what maturity level you consider this to be.

rename execute, fetch, and fetchall

These names are taken from DB-API 2.0, but the semantics differ enough that to use the same names is confusing. Specifically, in DB-API you always call execute before you call fetchone or fetchall.

Rename one_or_zero

postgres.py is a great library. one_or_zero is a bad method name.

It does not return 0.

one_or_none would be better.

Or maybe just one. It's a nice reflection of all.

Or maybe if you want to give Haskellites warm-fuzzies (if they get warm-fuzzies).

Or if you really like one_or_zero then I'll open a ticket to rename all to all_or_nothing. ;-)

maybe back_as should override dereferencing

The following returns an object of whatever type bar is: we dereference bar when it's the only field requested.

bar = db.one('select foo from bar')

But what about this?

bar = db.one('select foo from bar', back_as=dict)

Right now the dereferencing trumps the back_as, but @seanlinsley, at least, expected the back_as to bind tighter. I can see that. Anyone else?

get_cursor shouldn't take args

Right now get_cursor takes args and actually does an execute. It shouldn't, it should just return the cursor. This will make PostgresCursorContextManager simpler.

port to asyncpg

asyncpg is a database interface library designed specifically for PostgreSQL and Python/asyncio. asyncpg is an efficient, clean implementation of PostgreSQL server binary protocol for use with Python's asyncio framework.

https://github.com/MagicStack/asyncpg

allow typname to be a list

I have a model that I'd like to register for multiple types. The usecase is making a type that basically inherits from another type (though afaict Postgres doesn't implement type inheritance yet), overriding a foreign key field to actually subselect the record from the other table. By registering a single composite for multiple such types I could determine at query time whether I'd end up with the subselect or not.

roll back when strict one fails

If you do:

db.one("create table foo (bar text)")

you'll get a TooFew: Got -1 rows instead of 1. error, but the table will indeed be created. What would it be like to turn autocommit off and only commit db.one transactions when they returned exactly one row? What are the performance characteristics of autocommit?

url should default to ''

That would allow postgres.Postgres() to connect to the default database (localhost, current user).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.