Skip to content

Commit

Permalink
Merge pull request #204 from vutny/feature/sql
Browse files Browse the repository at this point in the history
Detect SQL dialects from *.sql files
  • Loading branch information
peti2001 authored Nov 4, 2021
2 parents 116c43a + 6bfe100 commit 5ffacc6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
5 changes: 3 additions & 2 deletions languagedetection/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ func buildExtensionToLanguageMap(input map[string][]string) map[string]string {
}

var extensionsWithMultipleLanguages = map[string]bool{
"m": true, // Objective-C, Matlab
"pl": true, // Perl, Prolog
"m": true, // Objective-C, Matlab
"pl": true, // Perl, Prolog
"sql": true, // Dialects of SQL
}

var fileExtensionMap = map[string][]string{
Expand Down
26 changes: 26 additions & 0 deletions languagedetection/analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,30 @@ var _ = Describe("Analyzer", func() {
Expect(l2).To(Equal("Dockerfile"))
})
})

Context("Detect language by file name", func() {
It("should detect SQL and PLpgSQL ", func() {
// Act
l1 := a.Detect("/home/something/get_pg_users.sql", []byte(`SELECT usename FROM pg_catalog.pg_user;`))
l2 := a.Detect("/home/something/create_pg_user.sql", []byte(`--
CREATE OR REPLACE FUNCTION __tmp_create_user()
RETURNS VOID
LANGUAGE plpgsql
AS
$$
BEGIN
IF NOT EXISTS (
SELECT
FROM pg_catalog.pg_user
WHERE usename = 'new_user') THEN
CREATE USER 'new_user';
END IF;
END;
$$;`))

// Assert
Expect(l1).To(Equal("SQL"))
Expect(l2).To(Equal("PLpgSQL"))
})
})
})

0 comments on commit 5ffacc6

Please sign in to comment.