Re: Change in datetime type casting
От | Daniele Varrazzo |
---|---|
Тема | Re: Change in datetime type casting |
Дата | |
Msg-id | CA+mi_8ZJ9o+tp03sbxw1+nayE+FVfv+a3cU8L78mz7fN3dXXzA@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Change in datetime type casting (Federico Di Gregorio <fog@dndg.it>) |
Список | psycopg |
On Mon, Jul 2, 2012 at 9:24 AM, Federico Di Gregorio <fog@dndg.it> wrote: > 2) Throw an exception if keys/values aren't strings and force the user > to convert the data before trying to send it to the hstore. We can definitely add a check to verify every key is a basestring and every value is a basestring or null (this is exactly the hstore domain). It is an extra iteration to be performed on the entire content of the dict though. Something on a slightly different note we could do: adapt takes a protocol as input (undocumented I believe, defaulting to ISQLQuote, currently the only protocol used): if we added a parameter to the protocol, defaulting to the current extensions.adapters we could have: - adaptation of hstore keys is performed on a limited set of datatypes: only str and unicode. Trying to pass another type in a dict would raise an adaptation error; - adaptation of hstore values is performed on the same types plus None; - if s.b. wanted to map other types into an hstore they can add other adapters just on the HstoreAdapter object (the object returned by register_adapter) - we can have adapters map per connection/cursor, other argument touched in this thread. So we stay strict in the default you have independently verified are the only sane default choice, allow for extension by users who know what they want to do and get a nice symmetry between adaptation and type casting. As an interface, register_adapter() could take an extra context as register_type() does: it could be a connection, a cursor or an HstoreAdapter (e.g. it could be whatever object exporting a method add_adapter() or something along this line). This is an idea of 3am after the PyBirra: if nothing makes sense here, please ignore. -- Daniele
В списке psycopg по дате отправления: