records icon indicating copy to clipboard operation
records copied to clipboard

API improvements

Open PauloPhagula opened this issue 8 years ago • 1 comments

Hello Kenneth,

First of all, please allow me to compliment you on your great work on records as well as all other for Humans projects.

I write this email because I've made a few additions/customizations to records for personal use, and I feel like perhaps I should "give it back" by sharing these improvements with you and the community.

I would summarize the changes in:

  • use records as the underlying supporting library, and on top of it, add an API that matches ezsql/wpdb (https://make.wordpress.org/core/tag/wpdb/) to make it even easier to perform a few common tasks like:
    • Getting timing on last query
    • Getting number of affected rows by most recent query
    • Getting last insert id
    • Get a single row/column by offset
    • Get a single value
    • Log queries
    • Automatically replace %f, %d by %s since Python's DB API spec doesn't support those parameter formats, but people are usually unaware of it Insert, updates and deletes like
db.insert('test_user', username='scott', password='tiger', created_at=datetime.datetime.now())
db.insert('test_user', {'username': 'JONES', 'password': 'STEEL'})
db.update('test_user', {'password': 'shepard'}, {'username': 'scott'})
db.delete('test_user', {'username': None}) # None is converted to NULL
db.delete('test_user', username=None)
  • The other significant change is that I've removed the dependency on sqlalchemy, and instead just use the native drivers (psycopg2, pymysql), but still allowing the user to connect using a DSN url. The code can be found on https://github.com/dareenzo/ezrecords

I haven't made a PR because first I'd like to get your consideration on the proposed changes. Since I already have the code functioning, porting should be straightforward once you've replied on whether you'd like to have these features on records too.

PauloPhagula avatar Jan 09 '17 01:01 PauloPhagula

@dareenzo the feature list seems really impressive.

On the other hand, the differences with records seems to be rather big, at least in following areas:

  • records prefers simplicity and supporting the most requested features. ezrecords supports many more features.
  • records relies on sqlalchemy while you try to avoid it.

Personally I feel, both "drinks" (records and ezrecords) are of excellent taste, but mixing them could result in a bit strange side effects.

For that reason I propose to close this issue, thank you for the offer and do "cherry-picking" at the moment, someone asks for specific feature from your menu.

@kennethreitz what do you think?

vlcinsky avatar Apr 26 '18 22:04 vlcinsky