Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #109735 > unrolled thread

Tie dictionary to database table?

Started by"Peter Heitzer" <peter.heitzer@rz.uni-regensburg.de>
First post2016-06-09 12:30 +0000
Last post2016-06-16 20:59 -0700
Articles 8 — 6 participants

Back to article view | Back to comp.lang.python


Contents

  Tie dictionary to database table? "Peter Heitzer" <peter.heitzer@rz.uni-regensburg.de> - 2016-06-09 12:30 +0000
    Re: Tie dictionary to database table? justin walters <walters.justin01@gmail.com> - 2016-06-09 06:09 -0700
    Re: Tie dictionary to database table? Michael Selik <michael.selik@gmail.com> - 2016-06-09 22:40 +0000
      Re: Tie dictionary to database table? "Peter Heitzer" <peter.heitzer@rz.uni-regensburg.de> - 2016-06-10 07:30 +0000
        Re: Tie dictionary to database table? Christian Gollwitzer <auriocus@gmx.de> - 2016-06-10 09:38 +0200
          Re: Tie dictionary to database table? "Peter Heitzer" <peter.heitzer@rz.uni-regensburg.de> - 2016-06-10 10:56 +0000
            Re: Tie dictionary to database table? Peter Otten <__peter__@web.de> - 2016-06-10 14:25 +0200
    Re: Tie dictionary to database table? Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-16 20:59 -0700

#109735 — Tie dictionary to database table?

From"Peter Heitzer" <peter.heitzer@rz.uni-regensburg.de>
Date2016-06-09 12:30 +0000
SubjectTie dictionary to database table?
Message-ID<drt5r8Ft1maU1@mid.individual.net>
In Perl there exists the tie mechanism for key/value type databases like
Berkeley db. Are there any python modules that can do the same for
a column of a mysql table?
Given the following table users:
(
username char(16) not null unique,
email char(128),
fullname char(64)
)

What I would like is if I write 

email['frank']='frank@middle-of-nowhere.org'

in my python script it generates a statement like
update users set email='frank@middle-of-nowhere.org' where username='frank';

Any hints to already existing modules are highly appreciated.



and have 

-- 
Dipl.-Inform(FH) Peter Heitzer, peter.heitzer@rz.uni-regensburg.de

[toc] | [next] | [standalone]


#109743

Fromjustin walters <walters.justin01@gmail.com>
Date2016-06-09 06:09 -0700
Message-ID<mailman.112.1465477759.2306.python-list@python.org>
In reply to#109735
It looks like you might be looking for an ORM. Have you checked out
sqlalchemy?

[toc] | [prev] | [next] | [standalone]


#109765

FromMichael Selik <michael.selik@gmail.com>
Date2016-06-09 22:40 +0000
Message-ID<mailman.126.1465512052.2306.python-list@python.org>
In reply to#109735
On Thu, Jun 9, 2016 at 9:10 AM justin walters <walters.justin01@gmail.com>
wrote:

> It looks like you might be looking for an ORM. Have you checked out
> sqlalchemy?
>

An ORM might be overkill. If you just want a persistent dictionary, just
use the shelve module. https://docs.python.org/3/library/shelve.html

[toc] | [prev] | [next] | [standalone]


#109773

From"Peter Heitzer" <peter.heitzer@rz.uni-regensburg.de>
Date2016-06-10 07:30 +0000
Message-ID<drv8l8Fb7nnU1@mid.individual.net>
In reply to#109765
Michael Selik <michael.selik@gmail.com> wrote:
>On Thu, Jun 9, 2016 at 9:10 AM justin walters <walters.justin01@gmail.com>
>wrote:

>> It looks like you might be looking for an ORM. Have you checked out
>> sqlalchemy?
>>

>An ORM might be overkill. If you just want a persistent dictionary, just
>use the shelve module. https://docs.python.org/3/library/shelve.html
That looks like tie in Perl. Unfortunately I have to use mysql as database
and I need concurrent read/write as the table may be modified by other
processes.
Meanwhile I have analized my demans a bit and modified the task so that I
need not read values but rather make updates to the tables.



-- 
Dipl.-Inform(FH) Peter Heitzer, peter.heitzer@rz.uni-regensburg.de

[toc] | [prev] | [next] | [standalone]


#109774

FromChristian Gollwitzer <auriocus@gmx.de>
Date2016-06-10 09:38 +0200
Message-ID<njdqq7$cr5$1@dont-email.me>
In reply to#109773
Am 10.06.16 um 09:30 schrieb Peter Heitzer:
> Michael Selik <michael.selik@gmail.com> wrote:
>> An ORM might be overkill. If you just want a persistent dictionary, just
>> use the shelve module. https://docs.python.org/3/library/shelve.html
> That looks like tie in Perl. Unfortunately I have to use mysql as database
> and I need concurrent read/write as the table may be modified by other
> processes.
> Meanwhile I have analized my demans a bit and modified the task so that I
> need not read values but rather make updates to the tables.

It wouldn't be that difficult to roll your own thing which does that; 
you just need to define __setitem__ and __getitem__ in your class which 
translates between the SQL call and the Python code.

	Christian

[toc] | [prev] | [next] | [standalone]


#109779

From"Peter Heitzer" <peter.heitzer@rz.uni-regensburg.de>
Date2016-06-10 10:56 +0000
Message-ID<drvkmoFdk2vU3@mid.individual.net>
In reply to#109774
Christian Gollwitzer <auriocus@gmx.de> wrote:
>Am 10.06.16 um 09:30 schrieb Peter Heitzer:
>> Michael Selik <michael.selik@gmail.com> wrote:
>>> An ORM might be overkill. If you just want a persistent dictionary, just
>>> use the shelve module. https://docs.python.org/3/library/shelve.html
>> That looks like tie in Perl. Unfortunately I have to use mysql as database
>> and I need concurrent read/write as the table may be modified by other
>> processes.
>> Meanwhile I have analized my demans a bit and modified the task so that I
>> need not read values but rather make updates to the tables.

>It wouldn't be that difficult to roll your own thing which does that; 
>you just need to define __setitem__ and __getitem__ in your class which 
>translates between the SQL call and the Python code.
That's a good idea. 



-- 
Dipl.-Inform(FH) Peter Heitzer, peter.heitzer@rz.uni-regensburg.de

[toc] | [prev] | [next] | [standalone]


#109781

FromPeter Otten <__peter__@web.de>
Date2016-06-10 14:25 +0200
Message-ID<mailman.134.1465561692.2306.python-list@python.org>
In reply to#109779
Peter Heitzer wrote:

> Christian Gollwitzer <auriocus@gmx.de> wrote:
>>Am 10.06.16 um 09:30 schrieb Peter Heitzer:
>>> Michael Selik <michael.selik@gmail.com> wrote:
>>>> An ORM might be overkill. If you just want a persistent dictionary,
>>>> just use the shelve module.
>>>> https://docs.python.org/3/library/shelve.html
>>> That looks like tie in Perl. Unfortunately I have to use mysql as
>>> database and I need concurrent read/write as the table may be modified
>>> by other processes.
>>> Meanwhile I have analized my demans a bit and modified the task so that
>>> I need not read values but rather make updates to the tables.
> 
>>It wouldn't be that difficult to roll your own thing which does that;
>>you just need to define __setitem__ and __getitem__ in your class which
>>translates between the SQL call and the Python code.
> That's a good idea.

There's an old recipe for sqlite3

http://code.activestate.com/recipes/576638-draft-for-an-sqlite3-based-dbm/

that you might adapt.

[toc] | [prev] | [next] | [standalone]


#110045

FromLawrence D’Oliveiro <lawrencedo99@gmail.com>
Date2016-06-16 20:59 -0700
Message-ID<44e1453f-58c1-4e4f-84fe-646262dfe5ac@googlegroups.com>
In reply to#109735
On Friday, June 10, 2016 at 12:30:47 AM UTC+12, Peter Heitzer wrote:
> What I would like is if I write 
> 
> email['frank']='frank@middle-of-nowhere.org'
> 
> in my python script it generates a statement like
> update users set email='frank@middle-of-nowhere.org' where username='frank';

That’s not a database, that’s a key-value store.

<http://blogcoward.com/images/blogcoward_com/WindowsLiveWriter/NoSQLlinksofinterest_10C52/fault-tolerance[1]_3.png>

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web