Skip to content

Commit

Permalink
Context type/proc fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
jfilby committed Aug 5, 2022
1 parent 2f2a0c3 commit 7ae4031
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 21 deletions.
25 changes: 21 additions & 4 deletions src/nexus/cmd/service/generate/modules/gen_context_procs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ proc generateContextProc*(
if module.nameInPascalCase != "NexusCore":

str &=
&" {module.nameInPascalCase}DbContext(dbConn: getDbConn())\n" &
"\n" &
&" {module.nameInCamelCase}Context.nexusCoreDbContext =\n" &
&" NexusCoreDbContext(dbConn: {module.nameInCamelCase}Context.db.dbConn)\n"
&" {module.nameInPascalCase}DbContext(dbConn: getDbConn())\n"

else:
str &=
Expand All @@ -87,6 +84,7 @@ proc generateContextProc*(
# For web-enabled modules or Nexus Core (which is a include web library procs)
if module.isWeb == true or
module.nameInPascalCase == "NexusCore":

str &=
"\n" &
&" {module.nameInCamelCase}Context.web =\n" &
Expand All @@ -99,6 +97,25 @@ proc generateContextProc*(
else:
str &= &" {module.nameInCamelCase}Context.nexusCoreDbContext))\n"

# For modules other than Nexus Core, create a Nexus Core context
if module.nameInPascalCase != "NexusCore":

str &=
"\n" &
&" {module.nameInCamelCase}Context.nexusCoreContext =\n" &
" NexusCoreContext(\n" &
" NexusCoreDbContext(\n" &
&" dbConn: {module.nameInCamelCase}Context.db.dbConn)"

if module.isWeb == true or
module.nameInPascalCase == "NexusCore":

str &=
",\n" &
&" web: {module.nameInCamelCase}Context.web"

str &= ")\n"

# Generate: return
str &=
"\n" &
Expand Down
4 changes: 2 additions & 2 deletions src/nexus/cmd/service/generate/modules/gen_context_type.nim
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ proc generateContextType*(
str &= "import options\n"

if module.nameInPascalCase != "NexusCore":
str &= "import nexus/core/types/model_types as nexus_core_model_types\n"
str &= "import nexus/core/types/context_type as nexus_core_context_type\n"

if module.isWeb == true or
module.nameInPascalCase == "NexusCore":
Expand All @@ -59,7 +59,7 @@ proc generateContextType*(
"\n"

if module.nameInPascalCase != "NexusCore":
str &= " nexusCoreDbContext*: NexusCoreDbContext\n" &
str &= " nexusCoreContext*: NexusCoreContext\n" &
"\n"

str &= " # Add your own context vars below this comment\n" &
Expand Down
9 changes: 6 additions & 3 deletions src/nexus/core_extras/service/module/context.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import nexus/core/data_access/db_conn
import core_extras/types/context_type
import core_extras/types/model_types

Expand All @@ -8,10 +9,12 @@ proc newNexusCoreExtrasContext*():
var nexusCoreExtrasContext = NexusCoreExtrasContext()

nexusCoreExtrasContext.db =
NexusCoreExtrasDbContext()
NexusCoreExtrasDbContext(dbConn: getDbConn())

nexusCoreExtrasContext.nexusCoreDbContext =
NexusCoreDbContext(dbConn: nexusCoreExtrasContext.db.dbConn)
nexusCoreExtrasContext.nexusCoreContext =
NexusCoreContext(
NexusCoreDbContext(
dbConn: nexusCoreExtrasContext.db.dbConn))

return nexusCoreExtrasContext

4 changes: 2 additions & 2 deletions src/nexus/core_extras/types/context_type.nim
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import nexus/core/types/model_types as nexus_core_model_types
import nexus/core/types/context_type as nexus_core_context_type
import model_types


type
NexusCoreExtrasContext* = object
db*: NexusCoreExtrasDbContext
nexusCoreDbContext*: NexusCoreDbContext
nexusCoreContext*: NexusCoreContext

# Add your own context vars below this comment

9 changes: 6 additions & 3 deletions src/nexus/crm/service/module/context.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import nexus/core/data_access/db_conn
import crm/types/context_type
import crm/types/model_types

Expand All @@ -8,10 +9,12 @@ proc newNexusCRMContext*():
var nexusCRMContext = NexusCRMContext()

nexusCRMContext.db =
NexusCRMDbContext()
NexusCRMDbContext(dbConn: getDbConn())

nexusCRMContext.nexusCoreDbContext =
NexusCoreDbContext(dbConn: nexusCRMContext.db.dbConn)
nexusCRMContext.nexusCoreContext =
NexusCoreContext(
NexusCoreDbContext(
dbConn: nexusCRMContext.db.dbConn))

return nexusCRMContext

4 changes: 2 additions & 2 deletions src/nexus/crm/types/context_type.nim
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import nexus/core/types/model_types as nexus_core_model_types
import nexus/core/types/context_type as nexus_core_context_type
import model_types


type
NexusCRMContext* = object
db*: NexusCRMDbContext
nexusCoreDbContext*: NexusCoreDbContext
nexusCoreContext*: NexusCoreContext

# Add your own context vars below this comment

9 changes: 6 additions & 3 deletions src/nexus/social/service/module/context.nim
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import nexus/core/data_access/db_conn
import social/types/context_type
import social/types/model_types

Expand All @@ -8,10 +9,12 @@ proc newNexusSocialContext*():
var nexusSocialContext = NexusSocialContext()

nexusSocialContext.db =
NexusSocialDbContext()
NexusSocialDbContext(dbConn: getDbConn())

nexusSocialContext.nexusCoreDbContext =
NexusCoreDbContext(dbConn: nexusSocialContext.db.dbConn)
nexusSocialContext.nexusCoreContext =
NexusCoreContext(
NexusCoreDbContext(
dbConn: nexusSocialContext.db.dbConn))

return nexusSocialContext

4 changes: 2 additions & 2 deletions src/nexus/social/types/context_type.nim
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import nexus/core/types/model_types as nexus_core_model_types
import nexus/core/types/context_type as nexus_core_context_type
import model_types


type
NexusSocialContext* = object
db*: NexusSocialDbContext
nexusCoreDbContext*: NexusCoreDbContext
nexusCoreContext*: NexusCoreContext

# Add your own context vars below this comment

0 comments on commit 7ae4031

Please sign in to comment.