-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathexample.sql
201 lines (177 loc) Β· 4.84 KB
/
example.sql
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
Sample DB for the import command. You can create an sqlite DB with the command:
$ sqlite3 example.db < example.sql
*/
CREATE TABLE files (
blob_id_a TEXT, repository_id_a TEXT, commit_hash_a TEXT, path_a TEXT, content_a TEXT, uast_a BLOB,
blob_id_b TEXT, repository_id_b TEXT, commit_hash_b TEXT, path_b TEXT, content_b TEXT, uast_b BLOB,
score DOUBLE PRECISION);
INSERT INTO files values (
'3a6e3a6e3a6e3a6e3a6e3a6e3a6e3a6e3a6e3a6e',
'github.com/bblfsh/dashboard.git',
'922e922e922e922e922e922e922e922e922e922e',
'project/src/a',
'Some text',
'uast1',
'3a6e3a6e3a6e3a6e3a6e3a6e3a6e3a6e3a6e3a6e',
'github.com/bblfsh/dashboard.git',
'922e922e922e922e922e922e922e922e922e922e',
'other_project/src/b',
'Some text
',
'uast2',
0.9512810301340767
);
INSERT INTO files values (
'3a6e3a6e3a6e3a6e3a6e3a6e3a6e3a6e3a6e3a6e',
'github.com/bblfsh/dashboard.git',
'922e922e922e922e922e922e922e922e922e922e',
'dashboard/src/services/api.js',
'import log from ''./log'';
const defaultServerUrl =
process.env.REACT_APP_SERVER_URL || ''http://0.0.0.0:9999/api'';
const apiUrl = url => `${defaultServerUrl}${url}`;
const unexpectedErrorMsg =
''Unexpected error contacting babelfish server. Please, try again.'';
export function parse(language, filename, code, query, serverUrl) {
return new Promise((resolve, reject) => {
return fetch(apiUrl(''/parse''), {
method: ''POST'',
headers: {
''Content-Type'': ''application/json'',
},
body: JSON.stringify({
server_url: serverUrl,
language,
filename,
content: code,
query,
}),
})
.then(resp => resp.json())
.then(({ status, errors, uast, language }) => {
if (status === 0) {
resolve({ uast, language });
} else {
reject(errors ? errors.map(normalizeError) : [''unexpected error'']);
}
})
.catch(err => {
log.error(err);
reject([unexpectedErrorMsg]);
});
});
}
export function listDrivers() {
return fetch(apiUrl(''/drivers''))
.then(checkStatus)
.then(resp => resp.json());
}
function checkStatus(resp) {
if (resp.status < 200 || resp.status >= 300) {
const error = new Error(resp.statusText);
error.response = resp;
throw error;
}
return resp;
}
function normalizeError(err) {
if (typeof err === ''object'' && err.hasOwnProperty(''message'')) {
return err.message;
} else if (typeof err === ''string'') {
return err;
}
return null;
}
export function getGist(gist) {
return new Promise((resolve, reject) => {
return fetch(apiUrl(''/gist?url='' + gist), {
method: ''GET'',
headers: {
''Content-Type'': ''application/json'',
},
})
.then(checkStatus)
.then(resp => resp.text())
.then(code => resolve(code))
.catch(err => {
log.error(err);
reject([err].map(normalizeError));
});
});
}
export function version(serverUrl) {
return fetch(apiUrl(`/version`), {
method: ''POST'',
headers: {
''Content-Type'': ''application/json'',
},
body: JSON.stringify({
server_url: serverUrl,
}),
})
.then(checkStatus)
.then(resp => resp.json())
.catch(err => {
log.error(err);
return Promise.reject([err].map(normalizeError));
});
}',
'',
'3a6e3a6e3a6e3a6e3a6e3a6e3a6e3a6e3a6e3a6e',
'github.com/bblfsh/dashboard.git',
'922e922e922e922e922e922e922e922e922e922e',
'dashboard/src/services/api.js',
'const defaultServerUrl =
process.env.REACT_APP_SERVER_URL || ''http://0.0.0.0:9999/api'';
const apiUrl = url => `${defaultServerUrl}${url}`;
const unexpectedErrorMsg =
''Unexpected error contacting babelfish server. Please, try again.'';
export function parse(language, code, serverUrl) {
return new Promise((resolve, reject) => {
return fetch(apiUrl(''/parse''), {
method: ''POST'',
headers: {
''Content-Type'': ''application/json''
},
body: JSON.stringify({
server_url: serverUrl,
language,
content: code
})
})
.then(resp => resp.json())
.then(({ status, errors, uast }) => {
if (status === ''ok'') {
resolve(uast);
} else {
reject(errors.map(normalizeError));
}
})
.catch(err => {
console.error(err);
reject([unexpectedErrorMsg]);
});
});
}
export function listDrivers() {
return fetch(apiUrl(''/drivers'')).then(checkStatus).then(resp => resp.json());
}
function checkStatus(resp) {
if (resp.status < 200 || resp.status >= 300) {
const error = new Error(resp.statusText);
error.response = resp;
throw error;
}
return resp;
}
function normalizeError(err) {
if (typeof err === ''object'' && err.hasOwnProperty(''message'')) {
return err.message;
} else if (typeof err === ''string'') {
return err;
}
return null;
}',
'',
0.9512810301340767);