]> git.jsancho.org Git - datasette-connectors.git/blob - tests/dummy.py
Merge pull request #1 from PyTables/dependabot/pip/datasette-0.46
[datasette-connectors.git] / tests / dummy.py
1 import datasette_connectors as dc
2
3
4 class DummyConnector(dc.Connector):
5     connector_type = 'dummy'
6
7     def table_names(self):
8         return ['table1', 'table2']
9
10     def hidden_table_names(self):
11         return []
12
13     def detect_spatialite(self):
14         return False
15
16     def view_names(self):
17         return []
18
19     def table_count(self, table_name):
20         return 2
21
22     def table_info(self, table_name):
23         return [
24             {
25                 'cid': 0,
26                 'name': 'c1',
27                 'type': 'integer',
28                 'notnull': False,
29                 'default_value': None,
30                 'is_pk': False,
31             },
32             {
33                 'cid': 1,
34                 'name': 'c2',
35                 'type': 'integer',
36                 'notnull': False,
37                 'default_value': None,
38                 'is_pk': False,
39             },
40             {
41                 'cid': 2,
42                 'name': 'c3',
43                 'type': 'integer',
44                 'notnull': False,
45                 'default_value': None,
46                 'is_pk': False,
47             },
48         ]
49
50     def detect_fts(self, table_name):
51         return False
52
53     def foreign_keys(self, table_name):
54         return []
55
56     def table_exists(self, table_name):
57         return table_name in ['table1', 'table2']
58
59     def table_definition(self, table_type, table_name):
60         return 'CREATE TABLE ' + table_name + ' (c1, c2, c3)'
61
62     def indices_definition(self, table_name):
63         return []
64
65     def execute(
66         self,
67         sql,
68         params=None,
69         truncate=False,
70         custom_time_limit=None,
71         page_size=None,
72         log_sql_errors=True,
73     ):
74         results = []
75         truncated = False
76         description = ()
77
78         if sql == 'select c1 from table1':
79             results = [
80                 {'c1': 10},
81                 {'c1': 20},
82             ]
83             description = (('c1',),)
84         elif sql == 'select c1, c2, c3 from table2 limit 51':
85             results = [
86                 {'c1': 100, 'c2': 120, 'c3': 130},
87                 {'c1': 200, 'c2': 220, 'c3': 230},
88             ]
89             description = (('c1',), ('c2',), ('c3',))
90         elif sql == "select * from (select c1, c2, c3 from table2 ) limit 0":
91             pass
92         elif sql == "select c1, count(*) as n from ( select c1, c2, c3 from table2 ) where c1 is not null group by c1 limit 31":
93             results = [
94                 {'c1': 100, 'n': 1},
95                 {'c1': 200, 'n': 1},
96             ]
97             description = (('c1',), ('n',))
98         elif sql == "select c2, count(*) as n from ( select c1, c2, c3 from table2 ) where c2 is not null group by c2 limit 31":
99             results = [
100                 {'c2': 120, 'n': 1},
101                 {'c2': 220, 'n': 1},
102             ]
103             description = (('c2',), ('n',))
104         elif sql == "select c3, count(*) as n from ( select c1, c2, c3 from table2 ) where c3 is not null group by c3 limit 31":
105             results = [
106                 {'c3': 130, 'n': 1},
107                 {'c3': 230, 'n': 1},
108             ]
109             description = (('c3',), ('n',))
110         elif sql == 'select date(c1) from ( select c1, c2, c3 from table2 ) where c1 glob "????-??-*" limit 100;':
111             pass
112         elif sql == "select c1, c2, c3 from blah limit 51":
113             raise dc.OperationalError("no such table: blah")
114         else:
115             raise Exception("Unexpected query:", sql)
116
117         return results, truncated, description