diff options
author | LukenShiro <lukenshiro@ngi.it> | 2010-05-12 17:38:49 +0200 |
---|---|---|
committer | David Somero <xgizzmo@slackbuilds.org> | 2010-05-12 17:38:49 +0200 |
commit | c3f4bf3112cfe038b68ad1f068085c0d51e5da54 (patch) | |
tree | c3e8a530b743a3c43e053a9f9b41e0aa7869cc50 /development | |
parent | 9e84a5fdc1c45e458b84a1c0d4a09fab46482eb9 (diff) |
development/pydblite: Updated for version 2.3
Diffstat (limited to 'development')
-rw-r--r-- | development/pydblite/README | 4 | ||||
-rw-r--r-- | development/pydblite/index.html | 207 | ||||
-rw-r--r-- | development/pydblite/index_fr.html | 148 | ||||
-rw-r--r-- | development/pydblite/pydblite.SlackBuild | 12 | ||||
-rw-r--r-- | development/pydblite/pydblite.info | 8 | ||||
-rw-r--r-- | development/pydblite/slack-desc | 4 |
6 files changed, 371 insertions, 12 deletions
diff --git a/development/pydblite/README b/development/pydblite/README index d315119df56b0..1038a7032a03d 100644 --- a/development/pydblite/README +++ b/development/pydblite/README @@ -3,3 +3,7 @@ PyDbLite (small footprint untyped database engine in python) PyDbLite is a pure-Python in-memory database engine, using Python list comprehensions as query language instead of SQL, which stores data in a cPickled file. + +You can also use PyDbLite with MySQL and SQLite, as backends. +In order to use MySQL's adapter you will need MySQL-python +(available on SlackBuilds.org). diff --git a/development/pydblite/index.html b/development/pydblite/index.html new file mode 100644 index 0000000000000..a7a7ccc6ca7c1 --- /dev/null +++ b/development/pydblite/index.html @@ -0,0 +1,207 @@ +<html>
+
+<head>
+<title>PyDbLite</title>
+</head>
+
+<body>
+
+<style type="text/css">
+body, td {
+ color: #000000;
+ background-color: #ffffff;
+ font-family: sans-serif;
+ font-size: 13;
+ }
+
+pre {
+ font-family: arial }
+
+li { padding-bottom:10;
+ }
+
+.python {
+ color:330099;
+ font-family: "Courier New";
+ }
+
+.console {
+ color:white;
+ background-color:black;
+ font-family: "Courier New";
+ padding : 3;
+ }
+
+td.navigation
+{ background-color: #99ccff;
+ font-weight: bold;
+ font-family: avantgarde, sans-serif;
+ font-size: 110%;
+ width: 90%}
+
+td.lnk { background-color: #99ccff;
+ font-size: 70%;
+ }
+
+ol { margin-left : 20px;
+ }
+
+</style>
+
+<table width="100%" cellspacing="0"><tr><td class="navigation" align="center">PyDbLite</td>
+<td class="lnk" align="right"></td>
+</tr></table>
+<p>PyDbLite is a pure-Python in-memory database engine, using Python list
+comprehensions as query language, instead of SQL
+
+<p>It consists of one small module, <code>PyDbLite.py</code>. The package also provides two modules,
+<code>SQLite.py</code> and <code>MySQL.py</code>. They use SQLite and MySQL backends with the
+same Pythonic syntax as the pure-Python PyDbLite engine
+
+<p>To install the package, just <a href="http://sourceforge.net/project/platformdownload.php?group_id=210258">download
+it</a> and install it by running <span class="console">>python setup.py install</span>
+
+<p><h2>Pure-Python engine</h2>
+
+<ul>
+<li> import class <CODE>Base</CODE> from module PyDbLite : <span class="python">from PyDbLite import Base</span>
+
+<li> create a database instance, passing it a path in the file system : <span class="python">db = Base('dummy')</span>
+
+<li>for a new database, define the field names : <span class="python">db.create('name','age','size')</span>
+
+<br>You don't have to define the field types. PyDbLite will accept any value that
+can be serialized by the <CODE>cPickle</CODE> module : strings, Unicode strings, integers,
+floats, dates and datetimes (instances of the <CODE>date</CODE> and <CODE>datetime</CODE> classes in the <CODE>datetime</CODE> module), user-defined classes, etc
+
+<li> if the base exists, open it : <span class="python">db.open()</span>
+
+<li> you can pass a parameter "mode" to the <CODE>create()</CODE> method, to specify what
+you want to do if the base already exists in the file system
+<ul>
+<li>mode = "open" : <span class="python">db.create('name','age','size',mode="open")</span>
+
+ opens the database and ignores the field definition
+
+<li> mode = "override" : <span class="python">db.create('name','age','size',mode="override")</span>
+
+ erases the existing base and creates a new one with the field definition
+
+<li> if mode is not specified and the base already exists, an <CODE>IOError</CODE> is raised
+</ul>
+
+<li> insert a new record
+<ul>
+<li> by keywords : <span class="python">db.insert(name='homer',age=23,size=1.84)</span>
+
+<br>If some fields are missing, they are initialized with the value <CODE>None</CODE>
+
+<li> by positional arguments : <span class="python">db.insert('homer',23,1.84)</span>
+
+<br>The arguments must be provided in the same order as in the <CODE>create()</CODE> method
+</ul>
+
+<li>save the changes on disk : <span class="python">db.commit()</span>
+<br>If you don't commit the changes, the insertion, deletion and update operations
+will not be saved on disk. To return to the previous version, just <span class="python">
+open()</span> it again (this is equivalent to rollback in transactional
+databases)
+
+<li> besides the fields passed to the <CODE>create()</CODE> method, an internal field called <CODE>__id__</CODE> is added. It is a integer which is guaranteed to be unique and unchanged for each record in the base, so that it can be used as the record identifier
+
+<li> another internal field called <CODE>__version__</CODE> is also managed by the database engine. It is a integer which is set to 0 when the record is created, then incremented by 1 each time the record is updated. This is used to detect concurrency control, for instance in a web application where 2 users select the same record and want to update it at the same time
+
+<li>the selection of records uses Python list comprehension syntax :
+<br><span class="python">recs = [ r for r in db if 30 > r['age'] >= 18 and r['size'] < 2 ]</span>
+
+<br>returns the records in the base where the age is between 18 and 30, and size is below 2 meters. The record is a dictionary, where the key is the field name and value is the field value
+
+<li> Python generator expression syntax can also be used :
+<br><span class="python">for r in (r for r in db if r['name'] in ('homer','marge') ):<br>
+ do_something_with(r)</span>
+
+<br>iterates on the records where the name is one of 'homer' or 'marge'
+
+<li> to iterate on all the records :
+<br><span class="python">for r in db:<br>
+ do_something_with(r)</span>
+
+<li> a record can be accessed by its identifier : <span class="python">record = db[rec_id]</span>
+
+returns the record such that record['__id__'] == rec_id
+
+<li> finally, a shortcut can be used for simple selections :
+<span class="python">db(key1=val1,key2=val2)</span> returns the list of records where the keys take the given value. It is equivalent to <span class="python">[ r for r in db if r["key1"]==val1 and r["key2"]==val2]</span>, but much more concise
+
+<li>to speed up selections, an index can be created on a field : <span class="python">db.create_index('age')</span>
+
+<br>When an index is created, the database instance has an attribute (here <CODE>_age</CODE> : note the heading underscore, to avoid name conflicts with internal names). This attribute is a dictionary-like object, where keys are the values taken by the field, and values are the records whose field values are egal to the key :
+<br><span class="python">records = db._age[23]</span> returns the list of records with age == 23
+
+<br>If no record has this value, lookup by this value returns an empty list
+
+<br>The index supports iteration on the field values, and the <CODE>keys()</CODE> method
+returns all existing values for the field
+
+<li>number of records in the base : <span class="python">len(db)</span>
+
+<li>to delete a record : <span class="python">db.delete(record)</span> or, if you know the record identifier : <span class="python">del db[rec_id]</span>
+
+<li>to delete a list of records : <span class="python">db.delete(list_of_records)</span>
+
+<br><CODE>list_of_records</CODE> can be any iterable (list, tuple, set, etc) yielding records
+
+<li>to update a record : <span class="python">db.update(record,age=24)</span>
+
+<li>to add a new field to an existing base and specify a default value : <span class="python">db.add_field('new_field'[,default=v])</span>. If no default is provided, the field value is <CODE>None</CODE>
+
+<li>to drop an existing field : <span class="python">db.drop_field('name')</span>
+
+<li>to get the list of fields : <span class="python">db.fields</span>
+
+</ul>
+
+<a name="sqlite"><p><h2>SQLite adapter</h2>
+<p>The only difference with the pure-Python module is the syntax to identify a <code>Base</code> and the need to specify field types on base creation
+<ul>
+<li>import the class <code>Base</code> :
+<span class="python">from PyDbLite.SQLite import Base</span>
+<li>connect to the SQLite database :
+<span class="python">connection = sqlite.connect("test")</span>
+<li>to create a <code>Base</code> instance (a table in the SQLite database) you pass the connection as argument : <span class="python">db = Base('dummy',connection)</code>
+<li>to create the base you must specify an SQLite field type : NULL, INTEGER, REAL, TEXT
+or BLOB : <span class="python">db.create(('name','TEXT'),('age',"INTEGER'),('size','REAL'))</span>
+<p>For convenience, you can also use the types DATE and DATETIME (or TIMESTAMP), the package will
+transparently manage the conversions between the <code>datetime.date</code> and
+<code>datetime.datetime</code> and the TEXT type
+</ul>
+<p>For record insertion, selection, update and deletion, the syntax is the same as above. The only difference is that you can't use the <code>drop_field()</code> method, since dropping fields is not supported by SQLite
+<p>The <code>Base</code> instance has an attribute <code>cursor</code>, so you can also execute
+SQL expressions by <span class="python">db.cursor.execute(some_sql)</span> and get the result
+by <span class="python">results = db.cursor.fetchall()</span>
+
+<p><a name="mysql"><h2>MySQL adapter</h2>
+<p>The only difference with the pure-Python module is the syntax to identify a <code>Base</code> and the need to specify field types on base creation
+<ul>
+<li>import the class <code>Base</code> :
+<span class="python">from PyDbLite.MySQL import Base</span>
+<li>connect to the SQLite database :
+<p><span class="python">import MySQLdb<br>
+ connection = MySQLdb.connect("localhost","root","admin")<br>
+ connection.cursor().execute("USE test")
+ </span> + +<li>pass the connection as argument to Base creation : <span class="python">db = Base('dummy',connection)</code>
+<li>to create a new base (a table in the MySQL database),specify a valid MySQL field type :
+<span class="python">db.create(('name','INTEGER'),('age',"INTEGER'),('size','REAL'))</span>
+</ul>
+
+<p>For record insertion, selection, update and deletion, adding or dropping fields,
+the syntax is the same as above
+<p>The <code>Base</code> instance has an attribute <code>cursor</code>, so you can also execute
+SQL expressions by <span class="python">db.cursor.execute(some_sql)</span> and get the result
+by <span class="python">results = db.cursor.fetchall()</span>
+
+
+</body>
+</html>
\ No newline at end of file diff --git a/development/pydblite/index_fr.html b/development/pydblite/index_fr.html new file mode 100644 index 0000000000000..112dabc8ff31e --- /dev/null +++ b/development/pydblite/index_fr.html @@ -0,0 +1,148 @@ +<html>
+
+<head>
+<title>PyDbLite</title>
+</head>
+
+<body>
+
+<style type="text/css">
+body, td {
+ color: #000000;
+ background-color: #ffffff;
+ font-family: sans-serif;
+ font-size: 13;
+ }
+
+pre {
+ font-family: arial }
+
+li { padding-bottom:10;
+ }
+
+.python {
+ color:330099;
+ font-family: "Courier New";
+ }
+
+td.navigation
+{ background-color: #99ccff;
+ font-weight: bold;
+ font-family: avantgarde, sans-serif;
+ font-size: 110%;
+ width: 90%}
+
+td.lnk { background-color: #99ccff;
+ font-size: 70%;
+ }
+
+td.tablename { vertical-align: top;
+ text-align: center;
+ font-weight: bold;
+ }
+
+ol { margin-left : 20px;
+ }
+
+</style>
+
+<table width="100%" cellspacing="0"><tr><td class="navigation" align="center">PyDbLite</td>
+<td class="lnk" align="right"><a href="index.html">English</a></td>
+</tr></table>
+<p>PyDbLite est un moteur de base de donn�es en m�moire, en pur Python, qui utilise les "list comprehensions" de Python comme langage de requ�tes au lieu de SQL
+
+<p>Il consiste en un seul petit module, PyDbLite.py. Pour l'installer, il suffit de le <a href="http://sourceforge.net/project/platformdownload.php?group_id=210258">t�l�charger</a> et de le mettre dans le r�pertoire <code>Lib/site-packages</code> de votre distribution Python
+
+<p>Utilisation :
+
+<ul>
+<li>importer la classe <CODE>Base</CODE> du module PyDbLite : <span class="python">from PyDbLite import Base</span>
+
+<li>cr�er une instance de base de donn�es,en passant un nom de fichier : <span class="python">db = Base('test')</span>
+
+<li>pour une nouvelle base, d�finissez les noms des champs : <span class="python">db.create('nom','age','taille')</span>
+
+<br>Vous n'avez pas � d�finir le type des champs. PyDbLite accepte toute valeur qui peut �tre s�rialis�e par le module <CODE>cPickle</CODE> : des cha�nes de caract�res, des cha�nes Unicode, des entiers, r�els, dates et dates-heures (instances des classes <CODE>date</CODE> et <CODE>datetime</CODE> dans le module <CODE>datetime</CODE>), des instances de classes d�finies par l'utilisateur, etc
+
+<li>si la base existe d�j�, pour l'ouvrir : <span class="python">db.open()</span>
+
+<li>on peut passer un param�tre "mode" � la m�thode <CODE>create()</CODE>, pour indiquer ce qu'il faut faire si la base existe d�j� sur le disque
+<ul>
+<li>mode = "open" : <span class="python">db.create('nom','age','taille',mode="open")</span>
+
+ouvre la base en ignorant la d�finition des champs
+
+<li> mode = "override" : <span class="python">db.create('nom','age','taille',mode="override")</span>
+
+efface la base existante et en cr�e une nouvelle avec les d�finitions de champs
+<li>si le mode n'est pas pr�cis� et que la base existe d�j�, une exception <CODE>IOError</CODE> est d�clench�e</ul>
+
+<li>insertion d'un nouvel enregistrement
+<ul>
+<li>par mots-cl�s : <span class="python">db.insert(nom='homer',age=23,taille=1.84)</span>
+
+<br>Si certains champs manquent, ils sont initialis�s � la valeur <CODE>None</CODE>
+
+<li>par arguments positionnels : <span class="python">db.insert('homer',23,1.84)</span>
+
+<br>Les arguments doivent �tre fournis dans le m�me ordre que dans la m�thode <CODE>create()</CODE>
+</ul>
+
+<li>pour sauvegarder les changements sur le disque : <span class="python">db.commit()</span>
+<br>Si vous ne confirmez pas les changements, les op�rations d'insertion, de suppression et de mise � jour ne seront pas sauvegard�s sur le disque
+
+<li>En plus des champs pass�s � la m�thode <CODE>create()</CODE>, un champ interne appel� <CODE>__id__</CODE> est ajout�. C'est un entier, unique et inchang� pour chaque enregistrement, il peut donc �tre utilis� comme identifiant pour l'enregistrement
+
+<li> un autre champ interne appel� <CODE>__version__</CODE> est �galement g�r� par le moteur de base de donn�es. Il s'agit d'un entier qui est initialis� � 0 quand l'enregistrement est cr��, et incr�ment� de 1 � chaque fois que l'enregistrement est mis � jour. Ceci sert pour la d�tection des acc�s concurrents, par exemple dans une application web dans laquelle deux utilisateurs veulent mettre � jour le m�me enregistrement en m�me temps
+
+<li>la s�lection d'enregistrements utilise la syntaxe des "list comprehensions" de Python :
+<br><span class="python">recs = [ r for r in db if 30 > r['age'] >= 18 and r['taille'] < 2 ]</span>
+
+<br>retourne les enregistrements de la base pour lesquels l'�ge est compris entre 18 et 30 ans, et la taille est inf�rieure � 2 m�tres. L'enregistrement est un dictionnaire, o� la cl� est le nom de champ et la valeur est la valeur de ce champ
+
+<li>la syntaxe des g�n�rateurs d'expression Python peut aussi �tre utilis�e :
+<br><span class="python">for r in (r for r in db if r['nom'] in ('homer','marge') ):<br>
+ faire_qqch_avec(r)</span>
+
+<br>it�re sur les enregistrements dont le nom est 'homer' ou 'marge'
+
+<li>pour it�rer sur tous les enregistrements :
+<br><span class="python">for r in db:<br>
+ fais_qqch_avec(r)</span>
+
+<li>on peut acc�der directement � un enregistrement par son identifiant : <span class="python">record = db[rec_id]</span>
+
+retourne l'enregistrement tel que record['__id__'] == rec_id
+
+<li> finalement, un raccourci peut �tre utilis� pour les s�lections simples :
+<span class="python">db(cle1=val1,cle2=val2)</span> renvoie la liste des enregistrements dont les cl�s prennent les valeurs donn�es. C'est �quivalent � <span class="python">[ r for r in db if r["cle1"]==val1 and r["cle2"]==val2]</span>, mais en beaucoup plus concis
+
+<li>pour acc�l�rer les s�lections, un index peut �tre cr�� sur un champ : <span class="python">db.create_index('age')</span>
+
+<br>Quand un index est cr��, l'instance de la base de donn�es a un attribut (ici <CODE>_age</CODE> : noter le signe de soulignement initial, pour �viter les conflits de noms avec des noms internes). Cet attribut est un objet de type dictionnaire, o� les cl�s sont les valeurs prises par le champ, et les valeurs sont les enregistrements dont le champ a la m�me valeur que la cl� :
+<br><span class="python">records = db._age[23]</span> retourne la liste des enregistrements avec age == 23
+
+<br>Si aucun enregistrement n'a cette valeur, la recherche par cette valeur retourne une liste vide
+
+<br>L'index supporte l'it�ration sur les valeurs du champ, et la m�thode <CODE>keys()</CODE> retourne toutes les valeurs existantes pour le champ
+
+<li>nombre d'enregistrements dans la base : <span class="python">len(db)</span>
+
+<li>pour supprimer un enregistrement : <span class="python">db.delete(record)</span> ou, si vous connaissez l'identifiant : <span class="python">del db[rec_id]</span>
+
+<li>pour supprimer une liste d'enregistrements : <span class="python">db.delete(liste_d_enregistrements)</span>
+
+<br><CODE>liste_d_enregistrements</CODE> peut �tre n'importe quel it�rable (liste, tuple, set, etc) qui produit des enregistrements
+
+<li>pour mettre � jour un enregistrement : <span class="python">db.update(record,age=24)</span>
+
+<li>pour ajouter un nouveau champ � une base existante et sp�cifier une valeur par d�faut : <span class="python">db.add_field('nouveau_champ'[,default=v])</span>. Si le d�faut n'est pas fourni, la valeur du champ est <CODE>None</CODE>
+
+<li>pour supprimer un champ existant : <span class="python">db.drop_field('nom')</span>
+
+<li>pour conna�tre la liste des champs : <span class="python">db.fields</span>
+
+</ul>
+
+</body>
+</html>
\ No newline at end of file diff --git a/development/pydblite/pydblite.SlackBuild b/development/pydblite/pydblite.SlackBuild index 8d1ac18a18852..b8acc776d42ad 100644 --- a/development/pydblite/pydblite.SlackBuild +++ b/development/pydblite/pydblite.SlackBuild @@ -2,7 +2,7 @@ # Slackware build script for pydblite -# Copyright 2007 LukenShiro <lukenshiro@ngi.it> +# Copyright 2007-8-9 LukenShiro <lukenshiro@ngi.it> # All rights reserved. # # Redistribution and use of this script, with or without modification, is @@ -23,9 +23,8 @@ # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. PRGNAM=pydblite -SRC_PRGNAM=PyDbLite -VERSION=2.1 -ARCH=${ARCH:-i486} +VERSION=${VERSION:-2.3} +ARCH=noarch BUILD=${BUILD:-1} TAG=${TAG:-_SBo} @@ -34,7 +33,8 @@ TMP=${TMP:-/tmp/SBo} PKG=$TMP/package-$PRGNAM OUTPUT=${OUTPUT:-/tmp} -DOCFILES="LICENCE.txt PKG-INFO $SRC_PRGNAM/doc/index.html $SRC_PRGNAM/doc/index_fr.html" +SRC_PRGNAM=PyDbLite +DOCFILES="PKG-INFO $CWD/index.html $CWD/index_fr.html" # SLKCFLAGS are not used @@ -46,7 +46,7 @@ cd $TMP rm -rf $SRC_PRGNAM-$VERSION unzip $CWD/$SRC_PRGNAM-$VERSION.zip cd $SRC_PRGNAM-$VERSION -#chown -R root:root . +chown -R root:root . chmod -R u+w,go+r-w,a-s . # Install .py source files diff --git a/development/pydblite/pydblite.info b/development/pydblite/pydblite.info index 4c9d984efa078..9957500047d97 100644 --- a/development/pydblite/pydblite.info +++ b/development/pydblite/pydblite.info @@ -1,8 +1,8 @@ PRGNAM="pydblite" -VERSION="2.1" +VERSION="2.3" HOMEPAGE="http://pydblite.sourceforge.net" -DOWNLOAD="http://downloads.sourceforge.net/pydblite/PyDbLite-2.1.zip" -MD5SUM="a9ae4fc68873d0d9641e06cdd3c24043" +DOWNLOAD="http://downloads.sourceforge.net/pydblite/PyDbLite-2.3.zip" +MD5SUM="b0bd2216f3667dced29f71dc879e18cb" MAINTAINER="LukenShiro" EMAIL="lukenshiro@ngi.it" -APPROVED="rworkman" +APPROVED="dsomero" diff --git a/development/pydblite/slack-desc b/development/pydblite/slack-desc index aef7a48382682..f67cc73aa87ca 100644 --- a/development/pydblite/slack-desc +++ b/development/pydblite/slack-desc @@ -5,7 +5,7 @@ # make exactly 11 lines for the formatting to be correct. It's also # customary to leave one space after the ':'. - |-----handy-ruler------------------------------------------------------| + |-----handy-ruler------------------------------------------------------| pydblite: PyDbLite (small footprint untyped database engine in python) pydblite: pydblite: PyDbLite is a pure-Python in-memory database engine, using @@ -14,6 +14,6 @@ pydblite: which stores data in a cPickled file. pydblite: pydblite: It is written by Pierre Quentel and released under BSD license. pydblite: -pydblite: http://pydblite.sourceforge.net pydblite: +pydblite: Homepage: http://pydblite.sourceforge.net pydblite: |