Skip to content

Commit da85514

Browse files
authored
docs: update examples (#938)
docs: update examples
2 parents 43c2c25 + 9ce8ce8 commit da85514

File tree

1 file changed

+20
-38
lines changed

1 file changed

+20
-38
lines changed

docs/using-gitbase/examples.md

Lines changed: 20 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,34 +18,30 @@ FROM refs
1818
WHERE ref_name = 'HEAD';
1919
```
2020

21-
## First commit on HEAD history for all repositories
21+
## Files in the first commit on HEAD history for all repositories
2222

2323
```sql
2424
SELECT file_path,
2525
ref_commits.repository_id
2626
FROM commit_files
2727
NATURAL JOIN ref_commits
28-
WHERE ref_commits.ref_name = 'HEAD'
29-
AND ref_commits.history_index = 0;
28+
WHERE ref_name = 'HEAD'
29+
AND history_index = 0;
3030
```
3131

3232
## Commits that appear in more than one reference
3333

3434
```sql
35-
SELECT *
36-
FROM
37-
(SELECT COUNT(c.commit_hash) AS num,
38-
c.commit_hash
39-
FROM ref_commits r
40-
NATURAL JOIN commits c
41-
GROUP BY c.commit_hash) t
42-
WHERE num > 1;
35+
SELECT COUNT(commit_hash) AS num, commit_hash
36+
FROM ref_commits
37+
GROUP BY commit_hash
38+
HAVING num > 1;
4339
```
4440

4541
## Get the number of blobs per HEAD commit
4642

4743
```sql
48-
SELECT COUNT(commit_hash),
44+
SELECT COUNT(commit_blob),
4945
commit_hash
5046
FROM ref_commits
5147
NATURAL JOIN commits
@@ -85,8 +81,8 @@ SELECT
8581
SUM(JSON_EXTRACT(LOC(file_path, blob_content), '$.Comments')) as comments,
8682
SUM(JSON_EXTRACT(LOC(file_path, blob_content), '$.Blanks')) as blanks,
8783
COUNT(1) as files
88-
FROM commit_files
89-
NATURAL JOIN refs
84+
FROM refs
85+
NATURAL JOIN commit_files
9086
NATURAL JOIN blobs
9187
WHERE ref_name='HEAD'
9288
GROUP BY lang;
@@ -98,13 +94,13 @@ GROUP BY lang;
9894
SELECT file_path,
9995
repository_id,
10096
blob_content
101-
FROM files
97+
FROM ref_commits
10298
NATURAL JOIN commit_files
103-
NATURAL JOIN ref_commits
99+
NATURAL JOIN files
104100
WHERE ref_name = 'HEAD'
105-
AND ref_commits.history_index BETWEEN 0 AND 5
106-
AND is_binary(blob_content) = FALSE
107-
AND files.file_path NOT REGEXP '^vendor.*'
101+
AND history_index BETWEEN 0 AND 5
102+
AND NOT IS_BINARY(blob_content)
103+
AND NOT IS_VENDOR(file_path)
108104
AND (blob_content REGEXP '(?i)facebook.*[\'\\"][0-9a-f]{32}[\'\\"]'
109105
OR blob_content REGEXP '(?i)twitter.*[\'\\"][0-9a-zA-Z]{35,44}[\'\\"]'
110106
OR blob_content REGEXP '(?i)github.*[\'\\"][0-9a-zA-Z]{35,40}[\'\\"]'
@@ -145,7 +141,7 @@ DROP INDEX files_lang_idx ON files;
145141

146142
This query will report how many lines of actual code (only code, not comments, blank lines or text) changed in the last commit of each repository.
147143

148-
```
144+
```sql
149145
SELECT
150146
repo,
151147
JSON_EXTRACT(stats, '$.Code.Additions') AS code_lines_added,
@@ -175,7 +171,7 @@ The output will be similar to this:
175171
This query will report how many lines of actual code (only code, not comments, blank lines or text) changed in each file of the last commit of each repository. It's similar to the previous example. `COMMIT_STATS` is an aggregation over the result of `COMMIT_FILE_STATS` so to speak.
176172
We will only report those files that whose language has been identified.
177173

178-
```
174+
```sql
179175
SELECT
180176
repo,
181177
JSON_UNQUOTE(JSON_EXTRACT(stats, '$.Path')) AS file_path,
@@ -210,29 +206,15 @@ First of all, you should check out the [bblfsh documentation](https://docs.sourc
210206

211207
Also, you can take a look to all the UDFs and their signatures in the [functions section](/docs/using-gitbase/functions.md)
212208

213-
## Extract all import paths for every *Go* file on *HEAD* reference
214-
215-
```sql
216-
SELECT repository_id,
217-
file_path,
218-
uast_extract(uast(blob_content, LANGUAGE(file_path), '//uast:Import/Path'), "Value") AS imports
219-
FROM commit_files
220-
NATURAL JOIN refs
221-
NATURAL JOIN blobs
222-
WHERE ref_name = 'HEAD'
223-
AND LANGUAGE(file_path) = 'Go'
224-
AND ARRAY_LENGTH(imports) > 0;
225-
```
226-
227209
## Extracting all identifier names
228210

229211
```sql
230212
SELECT file_path,
231213
uast_extract(uast(blob_content, LANGUAGE(file_path), '//uast:Identifier'), "Name") name
232-
FROM commit_files
233-
NATURAL JOIN refs
214+
FROM refs
215+
NATURAL JOIN commit_files
234216
NATURAL JOIN blobs
235-
WHERE ref_name='HEAD' AND LANGUAGE(file_path) = 'Go';
217+
WHERE ref_name = 'HEAD' AND LANGUAGE(file_path) = 'Go';
236218
```
237219

238220
As result, you will get an array showing a list of the retrieved information. Each element in the list matches a node in the given sequence of nodes having a value for that property. It means that the length of the properties list may not be equal to the length of the given sequence of nodes:

0 commit comments

Comments
 (0)