Skip to content

Commit a9f8b81

Browse files
committed
doc: add loc function
Signed-off-by: Máximo Cuadros <[email protected]>
1 parent 324c32e commit a9f8b81

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

docs/using-gitbase/examples.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ FROM
4242
WHERE num > 1;
4343
```
4444

45-
## Get the number of blobs per HEAD commit
45+
## Get the number of blobs per HEAD commit
4646

4747
```sql
4848
SELECT COUNT(commit_hash),
@@ -76,6 +76,22 @@ GROUP BY committer_email,
7676
repo_id;
7777
```
7878

79+
## Report of line count per file from HEAD references
80+
81+
```sql
82+
SELECT
83+
LANGUAGE(file_path, blob_content) as lang,
84+
SUM(JSON_EXTRACT(LOC(file_path, blob_content), '$.Code')) as code,
85+
SUM(JSON_EXTRACT(LOC(file_path, blob_content), '$.Comments')) as comments,
86+
SUM(JSON_EXTRACT(LOC(file_path, blob_content), '$.Blanks')) as blanks,
87+
COUNT(1) as files
88+
FROM commit_files
89+
NATURAL JOIN refs
90+
NATURAL JOIN blobs
91+
WHERE ref_name='HEAD'
92+
GROUP BY lang;
93+
```
94+
7995
## Files from first 6 commits from HEAD references that contains some key and are not in vendor directory
8096

8197
```sql
@@ -201,4 +217,4 @@ To kill a query that's currently running you can use the value in `Id`. If we we
201217

202218
```sql
203219
KILL QUERY 168;
204-
```
220+
```

docs/using-gitbase/functions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ To make some common tasks easier for the user, there are some functions to inter
1414
|`uast_xpath(blob, xpath) blob`| performs an XPath query over the given UAST nodes |
1515
|`uast_extract(blob, key) text array`| extracts information identified by the given key from the uast nodes |
1616
|`uast_children(blob) blob`| returns a flattened array of the children UAST nodes from each one of the UAST nodes in the given array |
17-
17+
|`loc(path, blob) json`| returns a JSON map, containing the lines of code of a file, separated in three categories: Code, Blank and Comment lines |
1818
## Standard functions
1919

2020
These are all functions that are available because they are implemented in `go-mysql-server`, used by gitbase.

0 commit comments

Comments
 (0)