-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathlinksdb.py
51 lines (40 loc) · 1.86 KB
/
linksdb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""Generate a sample project"""
from AndroidCodeGenerator.generator import Generator
from AndroidCodeGenerator.db_table import (Table, Column, ForeignKey,
Unique, Trigger)
from AndroidCodeGenerator.sql_validator import SQLTester
links = Table('Link').add_cols(Column('sha').text.not_null,
Column('url').text.not_null,
Column('timestamp').timestamp.not_null\
.default_current_timestamp,
Column('deleted').integer.not_null\
.default(0),
Column('synced').integer.not_null\
.default(0))
links.add_constraints(Unique('url').on_conflict_ignore,
Unique('sha').on_conflict_ignore)
'''
deltrigger = Trigger("tr_del_link").temp.if_not_exists
deltrigger.after.delete_on(links.name)
deltrigger.do_sql("INSERT INTO {table} (sha, url, timestamp, deleted) VALUES\
(old.sha, old.url, old.timestamp, 1)".format(table=synclinks.name))
intrigger = Trigger("tr_ins_link").temp.if_not_exists
intrigger.after.insert_on(links.name)
intrigger.do_sql("INSERT INTO {table} (sha, url, timestamp) \
VALUES (new.sha, new.url, new.timestamp)"\
.format(table=synclinks.name))
#uptrigger = Trigger("tr_upd_link").temp.if_not_exists
#uptrigger.after.update_on(links.name)
#uptrigger.do_sql("INSERT INTO {table} (sha, url, timestamp) \
#VALUES (new.sha, new.url, new.timestamp)"\
# .format(table=synclinks.name))
'''
s = SQLTester()
s.add_tables(links)
#s.add_triggers(deltrigger, intrigger)
s.test_create()
g = Generator(path='android-client/src/com/nononsenseapps/linksgcm/database',
pkg='com.nononsenseapps.linksgcm.database')
g.add_tables(links)
#g.add_triggers(deltrigger, intrigger)
g.write()