Revision bb4eafc6 pithos/backends/lib/sqlalchemy/public.py
b/pithos/backends/lib/sqlalchemy/public.py | ||
---|---|---|
32 | 32 |
# or implied, of GRNET S.A. |
33 | 33 |
|
34 | 34 |
from dbworker import DBWorker |
35 |
from sqlalchemy import Table, Column, String, MetaData |
|
35 |
from sqlalchemy import Table, Column, String, Integer, MetaData
|
|
36 | 36 |
from sqlalchemy.sql import select |
37 |
from sqlalchemy.schema import Index |
|
38 |
|
|
37 | 39 |
|
38 | 40 |
class Public(DBWorker): |
39 | 41 |
"""Paths can be marked as public.""" |
... | ... | |
42 | 44 |
DBWorker.__init__(self, **params) |
43 | 45 |
metadata = MetaData() |
44 | 46 |
columns=[] |
45 |
columns.append(Column('path', String(2048), index=True)) |
|
46 |
self.public = Table('public', metadata, *columns, mysql_engine='InnoDB') |
|
47 |
columns.append(Column('public_id', Integer, primary_key=True)) |
|
48 |
columns.append(Column('path', String(2048))) |
|
49 |
self.public = Table('public', metadata, *columns, mysql_engine='InnoDB', sqlite_autoincrement=True) |
|
50 |
# place an index on path |
|
51 |
Index('idx_public_path', self.public.c.path) |
|
47 | 52 |
metadata.create_all(self.engine) |
48 | 53 |
|
49 |
|
|
50 | 54 |
def public_set(self, path): |
51 | 55 |
s = self.public.select() |
52 | 56 |
s = s.where(self.public.c.path == path) |
... | ... | |
63 | 67 |
r = self.conn.execute(s) |
64 | 68 |
r.close() |
65 | 69 |
|
66 |
def public_check(self, path): |
|
67 |
s = select([self.public.c.path], self.public.c.path == path) |
|
70 |
def public_get(self, path): |
|
71 |
s = select([self.public.c.public_id], self.public.c.path == path) |
|
72 |
r = self.conn.execute(s) |
|
73 |
row = r.fetchone() |
|
74 |
r.close() |
|
75 |
if row: |
|
76 |
return row[0] |
|
77 |
return None |
|
78 |
|
|
79 |
def public_path(self, public): |
|
80 |
s = select([self.public.c.path], self.public.c.public_id == public) |
|
68 | 81 |
r = self.conn.execute(s) |
69 |
l = r.fetchone()
|
|
82 |
row = r.fetchone()
|
|
70 | 83 |
r.close() |
71 |
return bool(l) |
|
84 |
if row: |
|
85 |
return row[0] |
|
86 |
return None |
Also available in: Unified diff