1 from datasette_connectors.row import Row
2 from datasette_connectors.connectors import Connector
5 class DummyConnector(Connector):
6 _connector_type = 'dummy'
10 return ['table1', 'table2']
13 def table_columns(path, table):
14 return ['c1', 'c2', 'c3']
17 def get_all_foreign_keys(path):
19 'table1': {'incoming': [], 'outgoing': []},
20 'table2': {'incoming': [], 'outgoing': []},
24 def table_counts(path, *args, **kwargs):
35 for table in ['table1', 'table2']:
38 'columns': ['c1', 'c2', 'c3'],
44 'foreign_keys': {'incoming': [], 'outgoing': []},
47 return tables, views, _connector_type
51 def __init__(self, path):
54 def execute(self, sql, params=None, truncate=False, page_size=None, max_returned_rows=None):
61 if sql == 'select c1 from table1':
66 description = (('c1',),)
67 elif sql == 'select rowid, * from table2 order by rowid limit 51':
69 Row({'rowid': 1, 'c1': 100, 'c2': 120, 'c3': 130}),
70 Row({'rowid': 2, 'c1': 200, 'c2': 220, 'c3': 230})
72 description = (('rowid',), ('c1',), ('c2',), ('c3',))
73 elif sql == 'select count(*) from table2':
74 rows = [Row({'count(*)': 2})]
75 description = (('count(*)',),)
76 elif sql == """select distinct rowid from table2
77 where rowid is not null
83 description = (('rowid',),)
84 elif sql == """select distinct c1 from table2
91 description = (('c1',),)
92 elif sql == """select distinct c2 from table2
99 description = (('c2',),)
100 elif sql == """select distinct c3 from table2
107 description = (('c3',),)
108 elif sql == 'select sql from sqlite_master where name = :n and type=:t':
109 if params['t'] != 'view':
110 rows = [Row({'sql': 'CREATE TABLE ' + params['n'] + ' (c1, c2, c3)'})]
111 description = (('sql',),)
113 raise Exception("Unexpected query: %s" % sql)
115 return rows, truncated, description