53 lines
2.4 KiB
Forth
53 lines
2.4 KiB
Forth
(*
|
|
* This file is part of the ExtensionDsLab project.
|
|
* Copyright (c) 2017 LogicalHacking.com
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, version 3.
|
|
*
|
|
* This program is distributed in the hope that it will be useful, but
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*)
|
|
|
|
namespace LogicalHacking.ExtensionDsLab.Archive
|
|
|
|
open FSharp.Data.Sql
|
|
|
|
|
|
module SqlConnector =
|
|
let [<Literal>] DevelopmentDB = "aa-ac.sqlite"
|
|
let [<Literal>] FullDB = "full.sqlite"
|
|
let [<Literal>] DatabaseDir = "archive/db"
|
|
let [<Literal>] ArchiveDir = __SOURCE_DIRECTORY__
|
|
+ @"/../.."
|
|
// static (compile time) ConnectionString
|
|
let [<Literal>] ConnectionString = @"Data Source="
|
|
+ ArchiveDir
|
|
+ @"/" + DatabaseDir
|
|
+ @"/" + DevelopmentDB + @";Version=3"
|
|
// create a type alias with the connection string and database vendor settings
|
|
type Sql = SqlDataProvider<
|
|
ConnectionString = ConnectionString,
|
|
DatabaseVendor = Common.DatabaseProviderTypes.SQLITE,
|
|
// 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/%s;Version=3" (archiveDir dir ) DatabaseDir DevelopmentDB)
|
|
| Prod -> Sql.GetDataContext(sprintf "Data Source=%s/%s/%s;Version=3" (archiveDir dir ) DatabaseDir FullDB)
|
|
| Auto -> try
|
|
getCtx dir Prod
|
|
with
|
|
| _ -> getCtx dir Dev |