1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-08-02 20:15:26 +02:00

Continued MySQL/PostgreSQL store provider refactoring

Refactored, renamed, removed storage related code.

Basic smoke test passed for PostgreSQL whilst fully working on MySQL variants as per usual.
This commit is contained in:
HarveyKandola 2018-09-27 15:14:48 +01:00
parent b455e5eaf5
commit 97beb3f4d3
81 changed files with 1454 additions and 1497 deletions

View file

@ -18,13 +18,13 @@ import (
"github.com/documize/community/core/database"
"github.com/documize/community/core/env"
"github.com/documize/community/core/secrets"
"github.com/documize/community/domain"
"github.com/documize/community/domain/store"
"github.com/documize/community/edition/storage"
"github.com/jmoiron/sqlx"
)
// InitRuntime prepares runtime using command line and environment variables.
func InitRuntime(r *env.Runtime, s *domain.Store) bool {
func InitRuntime(r *env.Runtime, s *store.Store) bool {
// We need SALT to hash auth JWT tokens
if r.Flags.Salt == "" {
r.Flags.Salt = secrets.RandSalt()

View file

@ -16,8 +16,8 @@ import (
"fmt"
"github.com/documize/community/core/env"
"github.com/documize/community/domain"
"github.com/documize/community/domain/section"
"github.com/documize/community/domain/store"
"github.com/documize/community/edition/boot"
"github.com/documize/community/edition/logging"
"github.com/documize/community/embed"
@ -52,7 +52,7 @@ func main() {
rt.Product.License.Edition = "Community"
// setup store
s := domain.Store{}
s := store.Store{}
// parse settings from command line and environment
rt.Flags = env.ParseFlags()

View file

@ -19,7 +19,6 @@ import (
"strings"
"github.com/documize/community/core/env"
"github.com/documize/community/domain"
account "github.com/documize/community/domain/account"
activity "github.com/documize/community/domain/activity"
attachment "github.com/documize/community/domain/attachment"
@ -37,12 +36,13 @@ import (
search "github.com/documize/community/domain/search"
setting "github.com/documize/community/domain/setting"
space "github.com/documize/community/domain/space"
"github.com/documize/community/domain/store"
user "github.com/documize/community/domain/user"
_ "github.com/go-sql-driver/mysql" // the mysql driver is required behind the scenes
)
// SetMySQLProvider creates MySQL provider
func SetMySQLProvider(r *env.Runtime, s *domain.Store) {
func SetMySQLProvider(r *env.Runtime, s *store.Store) {
// Set up provider specific details and wire up data prividers.
r.StoreProvider = MySQLProvider{
ConnectionString: r.Flags.DBConn,
@ -296,7 +296,11 @@ func (p MySQLProvider) JSONEmpty() string {
// JSONGetValue returns JSON attribute selection syntax.
// Typically used in SELECT <my_json_field> query.
func (p MySQLProvider) JSONGetValue(column, attribute string) string {
return fmt.Sprintf("JSON_EXTRACT(%s,'$.%s')", column, attribute)
if len(attribute) > 0 {
return fmt.Sprintf("JSON_EXTRACT(%s,'$.%s')", column, attribute)
}
return fmt.Sprintf("JSON_EXTRACT(%s,'$')", column)
}
// VerfiyVersion checks to see if actual database meets

View file

@ -17,7 +17,6 @@ import (
"strings"
"github.com/documize/community/core/env"
"github.com/documize/community/domain"
account "github.com/documize/community/domain/account"
activity "github.com/documize/community/domain/activity"
attachment "github.com/documize/community/domain/attachment"
@ -35,6 +34,7 @@ import (
search "github.com/documize/community/domain/search"
setting "github.com/documize/community/domain/setting"
space "github.com/documize/community/domain/space"
"github.com/documize/community/domain/store"
user "github.com/documize/community/domain/user"
_ "github.com/lib/pq" // the mysql driver is required behind the scenes
)
@ -49,7 +49,7 @@ type PostgreSQLProvider struct {
}
// SetPostgreSQLProvider creates PostgreSQL provider
func SetPostgreSQLProvider(r *env.Runtime, s *domain.Store) {
func SetPostgreSQLProvider(r *env.Runtime, s *store.Store) {
// Set up provider specific details and wire up data prividers.
r.StoreProvider = PostgreSQLProvider{
ConnectionString: r.Flags.DBConn,
@ -270,7 +270,11 @@ func (p PostgreSQLProvider) JSONEmpty() string {
// JSONGetValue returns JSON attribute selection syntax.
// Typically used in SELECT <my_json_field> query.
func (p PostgreSQLProvider) JSONGetValue(column, attribute string) string {
return fmt.Sprintf("%s -> '%s'", column, attribute)
if len(attribute) > 0 {
return fmt.Sprintf("%s -> '%s'", column, attribute)
}
return fmt.Sprintf("%s", column)
}
// VerfiyVersion checks to see if actual database meets