-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from askgitdev/go-mod-fn
moving and renaming some packages 😬 - quite a big diff
- Loading branch information
Showing
93 changed files
with
552 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Package extensions provide implementation of the various underlying sqlite3 virtual tables [https://www.sqlite.org/vtab.html] and user defined functions | ||
// that askgit uses under-the-hood. This module can be side-effect-imported in other modules to include the functionality | ||
// of the sqlite3 extensions there. | ||
package extensions | ||
|
||
import ( | ||
"github.com/askgitdev/askgit/extensions/internal/enry" | ||
"github.com/askgitdev/askgit/extensions/internal/git" | ||
"github.com/askgitdev/askgit/extensions/internal/github" | ||
"github.com/askgitdev/askgit/extensions/internal/golang" | ||
"github.com/askgitdev/askgit/extensions/internal/helpers" | ||
"github.com/askgitdev/askgit/extensions/options" | ||
"go.riyazali.net/sqlite" | ||
) | ||
|
||
func RegisterFn(fns ...options.OptionFn) func(ext *sqlite.ExtensionApi) (_ sqlite.ErrorCode, err error) { | ||
var opt = &options.Options{} | ||
for _, fn := range fns { | ||
fn(opt) | ||
} | ||
|
||
// return an extension function that register modules with sqlite when this package is loaded | ||
return func(ext *sqlite.ExtensionApi) (_ sqlite.ErrorCode, err error) { | ||
// register the git tables | ||
if sqliteErr, err := git.Register(ext, opt); err != nil { | ||
return sqliteErr, err | ||
} | ||
|
||
// only conditionally register the utility functions | ||
if opt.ExtraFunctions { | ||
if sqliteErr, err := helpers.Register(ext, opt); err != nil { | ||
return sqliteErr, err | ||
} | ||
|
||
if sqliteErr, err := enry.Register(ext, opt); err != nil { | ||
return sqliteErr, err | ||
} | ||
|
||
if sqliteErr, err := golang.Register(ext, opt); err != nil { | ||
return sqliteErr, err | ||
} | ||
} | ||
|
||
// conditionally register the GitHub functionality | ||
if opt.GitHub { | ||
if sqliteErr, err := github.Register(ext, opt); err != nil { | ||
return sqliteErr, err | ||
} | ||
} | ||
|
||
return sqlite.SQLITE_OK, nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package enry | ||
|
||
import ( | ||
"github.com/askgitdev/askgit/extensions/options" | ||
"github.com/pkg/errors" | ||
"go.riyazali.net/sqlite" | ||
) | ||
|
||
// Register registers enry related functionality as a SQLite extension | ||
func Register(ext *sqlite.ExtensionApi, _ *options.Options) (_ sqlite.ErrorCode, err error) { | ||
var fns = map[string]sqlite.Function{ | ||
"enry_detect_language": &EnryDetectLanguage{}, | ||
"enry_is_binary": &EnryIsBinary{}, | ||
"enry_is_configuration": &EnryIsConfiguration{}, | ||
"enry_is_documentation": &EnryIsDocumentation{}, | ||
"enry_is_dot_file": &EnryIsDotFile{}, | ||
"enry_is_generated": &EnryIsGenerated{}, | ||
"enry_is_image": &EnryIsImage{}, | ||
"enry_is_test": &EnryIsTest{}, | ||
"enry_is_vendor": &EnryIsVendor{}, | ||
} | ||
|
||
for name, fn := range fns { | ||
if err = ext.CreateFunction(name, fn); err != nil { | ||
return sqlite.SQLITE_ERROR, errors.Wrapf(err, "failed to register %q function", name) | ||
} | ||
} | ||
|
||
return sqlite.SQLITE_OK, nil | ||
} |
2 changes: 1 addition & 1 deletion
2
...es/internal/funcs/enry_detect_language.go → ...ons/internal/enry/enry_detect_language.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package funcs | ||
package enry | ||
|
||
import ( | ||
"github.com/go-enry/go-enry/v2" | ||
|
4 changes: 2 additions & 2 deletions
4
...ternal/funcs/enry_detect_language_test.go → ...nternal/enry/enry_detect_language_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tables/internal/funcs/enry_is_binary.go → extensions/internal/enry/enry_is_binary.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package funcs | ||
package enry | ||
|
||
import ( | ||
"github.com/go-enry/go-enry/v2" | ||
|
4 changes: 2 additions & 2 deletions
4
tables/internal/funcs/enry_is_binary_test.go → ...ions/internal/enry/enry_is_binary_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...s/internal/funcs/enry_is_configuration.go → ...ns/internal/enry/enry_is_configuration.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package funcs | ||
package enry | ||
|
||
import ( | ||
"github.com/go-enry/go-enry/v2" | ||
|
4 changes: 2 additions & 2 deletions
4
...ernal/funcs/enry_is_configuration_test.go → ...ternal/enry/enry_is_configuration_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...s/internal/funcs/enry_is_documentation.go → ...ns/internal/enry/enry_is_documentation.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package funcs | ||
package enry | ||
|
||
import ( | ||
"github.com/go-enry/go-enry/v2" | ||
|
4 changes: 2 additions & 2 deletions
4
...ernal/funcs/enry_is_documentation_test.go → ...ternal/enry/enry_is_documentation_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tables/internal/funcs/enry_is_dot_file.go → extensions/internal/enry/enry_is_dot_file.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package funcs | ||
package enry | ||
|
||
import ( | ||
"github.com/go-enry/go-enry/v2" | ||
|
4 changes: 2 additions & 2 deletions
4
...s/internal/funcs/enry_is_dot_file_test.go → ...ns/internal/enry/enry_is_dot_file_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tables/internal/funcs/enry_is_generated.go → ...nsions/internal/enry/enry_is_generated.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package funcs | ||
package enry | ||
|
||
import ( | ||
"github.com/go-enry/go-enry/v2" | ||
|
4 changes: 2 additions & 2 deletions
4
.../internal/funcs/enry_is_generated_test.go → ...s/internal/enry/enry_is_generated_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tables/internal/funcs/enry_is_image.go → extensions/internal/enry/enry_is_image.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package funcs | ||
package enry | ||
|
||
import ( | ||
"github.com/go-enry/go-enry/v2" | ||
|
4 changes: 2 additions & 2 deletions
4
tables/internal/funcs/enry_is_image_test.go → ...sions/internal/enry/enry_is_image_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tables/internal/funcs/enry_is_test_file.go → ...nsions/internal/enry/enry_is_test_file.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package funcs | ||
package enry | ||
|
||
import ( | ||
"github.com/go-enry/go-enry/v2" | ||
|
4 changes: 2 additions & 2 deletions
4
.../internal/funcs/enry_is_test_file_test.go → ...s/internal/enry/enry_is_test_file_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
tables/internal/funcs/enry_is_vendor.go → extensions/internal/enry/enry_is_vendor.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package funcs | ||
package enry | ||
|
||
import ( | ||
"github.com/go-enry/go-enry/v2" | ||
|
4 changes: 2 additions & 2 deletions
4
tables/internal/funcs/enry_is_vendor_test.go → ...ions/internal/enry/enry_is_vendor_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package enry | ||
|
||
import ( | ||
"database/sql" | ||
"log" | ||
"os" | ||
"testing" | ||
|
||
_ "github.com/askgitdev/askgit/pkg/sqlite" | ||
"go.riyazali.net/sqlite" | ||
) | ||
|
||
// FixtureDatabase represents the database connection to run the test against | ||
var FixtureDatabase *sql.DB | ||
|
||
func init() { | ||
// register sqlite extension when this package is loaded | ||
sqlite.Register(func(ext *sqlite.ExtensionApi) (_ sqlite.ErrorCode, err error) { | ||
return Register(ext, nil) | ||
}) | ||
} | ||
|
||
func TestMain(m *testing.M) { | ||
var err error | ||
if FixtureDatabase, err = sql.Open("sqlite3", "file:testing.db?mode=memory"); err != nil { | ||
log.Fatalf("failed to open database connection: %v", err) | ||
} | ||
|
||
os.Exit(m.Run()) | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package git | ||
|
||
import ( | ||
"github.com/askgitdev/askgit/extensions/internal/git/native" | ||
"github.com/askgitdev/askgit/extensions/options" | ||
"github.com/pkg/errors" | ||
"go.riyazali.net/sqlite" | ||
) | ||
|
||
// Register registers git related functionality as a SQLite extension | ||
func Register(ext *sqlite.ExtensionApi, opt *options.Options) (_ sqlite.ErrorCode, err error) { | ||
// register virtual table modules | ||
var modules = map[string]sqlite.Module{ | ||
"commits": &LogModule{Locator: opt.Locator, Context: opt.Context}, | ||
"refs": &RefModule{Locator: opt.Locator, Context: opt.Context}, | ||
"stats": native.NewStatsModule(opt.Locator, opt.Context), | ||
"files": native.NewFilesModule(opt.Locator, opt.Context), | ||
"blame": native.NewBlameModule(opt.Locator, opt.Context), | ||
} | ||
|
||
for name, mod := range modules { | ||
if err = ext.CreateModule(name, mod); err != nil { | ||
return sqlite.SQLITE_ERROR, errors.Wrapf(err, "failed to register %q module", name) | ||
} | ||
} | ||
|
||
var fns = map[string]sqlite.Function{ | ||
"commit_from_tag": &CommitFromTagFn{}, | ||
} | ||
|
||
for name, fn := range fns { | ||
if err = ext.CreateFunction(name, fn); err != nil { | ||
return sqlite.SQLITE_ERROR, errors.Wrapf(err, "failed to register %q function", name) | ||
} | ||
} | ||
|
||
return sqlite.SQLITE_OK, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.