Skip to content

Commit 09bc815

Browse files
authored
Merge pull request #379 from ajnavarro/doc/add-examples
Documentation: Add more examples
2 parents 4af9f82 + b6ef2af commit 09bc815

File tree

1 file changed

+55
-8
lines changed

1 file changed

+55
-8
lines changed

docs/using-gitbase/examples.md

+55-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,22 @@ WHERE commits.commit_author_name = 'Javi Fontan' AND refs.ref_name='HEAD';
1212
## Get all the HEAD references from all the repositories
1313

1414
```sql
15-
SELECT * FROM refs WHERE ref_name = 'HEAD'
15+
SELECT * FROM refs WHERE ref_name = 'HEAD';
16+
```
17+
18+
## First commit on HEAD history for all repositories
19+
20+
```sql
21+
SELECT
22+
file_path,
23+
ref_commits.repository_id
24+
FROM
25+
commit_files
26+
NATURAL JOIN
27+
ref_commits
28+
WHERE
29+
ref_commits.ref_name = 'HEAD'
30+
AND ref_commits.index = 0;
1631
```
1732

1833
## Commits that appear in more than one reference
@@ -24,7 +39,7 @@ SELECT * FROM (
2439
INNER JOIN commits c
2540
ON r.commit_hash = c.commit_hash
2641
GROUP BY c.commit_hash
27-
) t WHERE num > 1
42+
) t WHERE num > 1;
2843
```
2944

3045
## Get the number of blobs per HEAD commit
@@ -36,7 +51,7 @@ INNER JOIN commits c
3651
ON r.ref_name = 'HEAD' AND r.commit_hash = c.commit_hash
3752
INNER JOIN commit_blobs cb
3853
ON cb.commit_hash = c.commit_hash
39-
GROUP BY c.commit_hash
54+
GROUP BY c.commit_hash;
4055
```
4156

4257
## Get commits per committer, per month in 2015
@@ -53,29 +68,61 @@ FROM (
5368
ON YEAR(c.committer_when) = 2015 AND r.commit_hash = c.commit_hash
5469
WHERE r.ref_name = 'HEAD'
5570
) as t
56-
GROUP BY committer_email, month, repo_id
71+
GROUP BY committer_email, month, repo_id;
72+
```
73+
74+
## Files from first 6 commits from HEAD references that contains some key and are not in vendor directory
75+
76+
```sql
77+
select
78+
files.file_path,
79+
ref_commits.repository_id,
80+
files.blob_content
81+
FROM
82+
files
83+
NATURAL JOIN
84+
commit_files
85+
NATURAL JOIN
86+
ref_commits
87+
WHERE
88+
ref_commits.ref_name = 'HEAD'
89+
AND ref_commits.index BETWEEN 0 AND 5
90+
AND is_binary(blob_content) = false
91+
AND files.file_path NOT REGEXP '^vendor.*'
92+
AND (
93+
blob_content REGEXP '(?i)facebook.*[\'\\"][0-9a-f]{32}[\'\\"]'
94+
OR blob_content REGEXP '(?i)twitter.*[\'\\"][0-9a-zA-Z]{35,44}[\'\\"]'
95+
OR blob_content REGEXP '(?i)github.*[\'\\"][0-9a-zA-Z]{35,40}[\'\\"]'
96+
OR blob_content REGEXP 'AKIA[0-9A-Z]{16}'
97+
OR blob_content REGEXP '(?i)reddit.*[\'\\"][0-9a-zA-Z]{14}[\'\\"]'
98+
OR blob_content REGEXP '(?i)heroku.*[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}'
99+
OR blob_content REGEXP '.*-----BEGIN PRIVATE KEY-----.*'
100+
OR blob_content REGEXP '.*-----BEGIN RSA PRIVATE KEY-----.*'
101+
OR blob_content REGEXP '.*-----BEGIN DSA PRIVATE KEY-----.*'
102+
OR blob_content REGEXP '.*-----BEGIN OPENSSH PRIVATE KEY-----.*'
103+
);
57104
```
58105

59106
## Create an index for columns on a table
60107

61108
You can create an index either on a specific column or on several columns:
62109

63110
```sql
64-
CREATE INDEX commits_hash_idx ON commits USING pilosa (commit_hash)
111+
CREATE INDEX commits_hash_idx ON commits USING pilosa (commit_hash);
65112

66-
CREATE INDEX files_commit_path_blob_idx ON commit_files USING pilosa (commit_hash, file_path, blob_hash)
113+
CREATE INDEX files_commit_path_blob_idx ON commit_files USING pilosa (commit_hash, file_path, blob_hash);
67114
```
68115

69116
## Create an index for an expression on a table
70117

71118
Note that just one expression at a time is allowed to be indexed.
72119

73120
```sql
74-
CREATE INDEX files_lang_idx ON files USING pilosa (language(file_path, blob_content))
121+
CREATE INDEX files_lang_idx ON files USING pilosa (language(file_path, blob_content));
75122
```
76123

77124
## Drop a table's index
78125

79126
```sql
80-
DROP INDEX files_lang_idx ON files
127+
DROP INDEX files_lang_idx ON files;
81128
```

0 commit comments

Comments
 (0)