Ask HN: How to find occurrences of a DB model being used in a monolith?
Hi HN,
I'm looking for a way to find any usage of a specific DB model in a monolith - I would prefer to have a tool that scans the files and input/outputs the following:
Input:
- files to scan I.E ["./src", "./test", ...]
- what to scan for I.E ["ExampleModel.", "models.ExampleModel.", ...]
- exclude from scan I.E ["./src/example-folder", ...]
Results:
- From folder: "./src":
- Number of occurrences: *number*
- Occurrences: string[] of file paths
- From folder: "./test": - Number of occurrences: *number*
- Occurrences: string[] of file paths
This needs to be something I can write in Javascript or Python. Or preferably if you already know of such a tool please point me to it! :DWould appreciate any idea, comment or suggestion! Thanks :)
(
2 comments
| on HN
)
just grep implies certain features not available with all grep versions
* not clear what number of occurrences refers to:
a) 6/10 search strings found in directory files
b) 600 total matches found in 4/10 files in directory
example below assumes "600" is what's wanted.
* "occurrences: string[] ":
provide just the matching string & number of time occurs in fileor include the "0" matches too?
in given example, "0" occurrences are "dropped"
-----
initial stuff:
example shell command preceded by #
file with list of paths to use, one per line -> dirscan.txt (directory scans)
file with list of paths to exclude, one per line -> dirskip.txt (directory excludes)
file with list of strings to mach, one per line -> strchk.txt (string matches)
----
command sequence outline:
1.) non-grep: from moreutilities, combine preserves order & no need to sort
# combine dirscan.txt not dirskip.txt
2.) a) use find command to eliminate some edge cases while walking list of sorted directories from #1 to create sorted directory/files list in file dirlist.txt
( some edge cases: special files, no permissions, etc.)
b) use dirlist.txt with find: