From e7103c3e5b4da9abf53450864622b52dc6674de1 Mon Sep 17 00:00:00 2001 From: "Achim D. Brucker" Date: Fri, 11 Aug 2017 13:52:03 +0100 Subject: [PATCH] New method for obtaining db context (getCtx) that supports development and productive database. --- .../SqlConnector.fs | 20 ++++++++++++++++--- src/scripts/example.fsx | 4 +--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/LogicalHacking.ExtensionDsLab/SqlConnector.fs b/src/LogicalHacking.ExtensionDsLab/SqlConnector.fs index 368e225..db63283 100644 --- a/src/LogicalHacking.ExtensionDsLab/SqlConnector.fs +++ b/src/LogicalHacking.ExtensionDsLab/SqlConnector.fs @@ -24,10 +24,11 @@ module SqlConnector = let [] DevelopmentDB = "aa-ac.sqlite" let [] FullDB = "full.sqlite" let [] DatabaseDir = "archive/db" + let [] ArchiveDir = @"Data Source=" + + __SOURCE_DIRECTORY__ + + @"/../.." // static (compile time) ConnectionString - let [] ConnectionString = @"Data Source=" - + __SOURCE_DIRECTORY__ - + @"/../.." + let [] ConnectionString = ArchiveDir + @"/" + DatabaseDir + @"/" + DevelopmentDB + @";Version=3" // create a type alias with the connection string and database vendor settings @@ -37,3 +38,16 @@ module SqlConnector = // ResolutionPath = ResolutionPath, IndividualsAmount = 500, UseOptionTypes = true > + + + type Db = Dev | Prod | Auto + let rec getCtx dir = let archiveDir = function + | None -> ArchiveDir + | Some s -> s + function + | Dev -> Sql.GetDataContext(sprintf "Data Source=%s/%s;Version=3" (archiveDir dir ) DevelopmentDB) + | Prod -> Sql.GetDataContext(sprintf "Data Source=%s/%s;Version=3" (archiveDir dir ) DevelopmentDB) + | Auto -> try + getCtx dir Prod + with + | _ -> getCtx dir Dev \ No newline at end of file diff --git a/src/scripts/example.fsx b/src/scripts/example.fsx index d3aa817..6942f1c 100644 --- a/src/scripts/example.fsx +++ b/src/scripts/example.fsx @@ -30,9 +30,7 @@ open LogicalHacking.ExtensionDsLab.Archive.SqlConnector #load "../../packages/FsLab/Themes/DefaultWhite.fsx" #load "../../packages/FsLab/FsLab.fsx" - - -let Ctx = Sql.GetDataContext() // ResolutionPath,ConnectionString) // dynamic ResolutionPath and ConnectionString +let Ctx = getCtx None Auto let getDownloads extid = query { for order in Ctx.Main.Extension do