Refactoring: separated core database connection and data queries.

This commit is contained in:
Achim D. Brucker 2018-07-15 07:27:26 +01:00
parent 280235f55c
commit b68f0ee019
5 changed files with 47 additions and 24 deletions

View File

@ -19,26 +19,8 @@
namespace LogicalHacking.ExtensionDsLab.Archive
open FSharp.Data.Sql
open System.IO
module SqlConnector =
[<Literal>]
let ConnectionStringName = @"ProductionExtensionDB"
[<Literal>]
let ResolutionPath = __SOURCE_DIRECTORY__ + @"/../../packages/MySql.Data/lib/net452"
// create a type alias with the connection string and database vendor settings
type ExtensionDbProvider = SqlDataProvider<
DatabaseVendor = Common.DatabaseProviderTypes.MYSQL,
ConnectionStringName = ConnectionStringName,
ResolutionPath = ResolutionPath,
IndividualsAmount = 500,
UseOptionTypes = true >
type ExtensionDbType = ExtensionDbProvider.dataContext
let getDownloads (ctx:ExtensionDbType) extid =
module ExtensionCore =
let getDownloads (ctx:MySqlConnector.ExtensionDbType) extid =
query {
for order in ctx.Extensions.Extension do
where (order.Extid = extid)
@ -48,7 +30,7 @@ module SqlConnector =
download.Value))
|> Seq.toArray
let getAllExtIds (ctx:ExtensionDbType) =
let getAllExtIds (ctx:MySqlConnector.ExtensionDbType) =
query {
for ext in ctx.Extensions.Extension do
select ext.Extid

View File

@ -35,7 +35,7 @@ open System.Configuration
[<AutoOpen>]
module ScriptConfig=
open LogicalHacking.ExtensionDsLab.Archive.SqlConnector
open LogicalHacking.ExtensionDsLab.Archive.MySqlConnector
let connectionStringOrDefault ctx =
let map = new ExeConfigurationFileMap(ExeConfigFilename = __SOURCE_DIRECTORY__ + "/app.config")

View File

@ -16,7 +16,8 @@
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<Compile Include="SqlConnector.fs" />
<Compile Include="MySqlConnector.fs" />
<Compile Include="ExtensionCore.fs" />
<None Include="Script.fsx" />
<None Include="ExtensionsDsLab.fsx" />
<None Include="paket.references" />

View File

@ -0,0 +1,39 @@
(*
* 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/>.
*
* SPDX-License-Identifier: GPL-3.0-or-later
*)
namespace LogicalHacking.ExtensionDsLab.Archive
open FSharp.Data.Sql
open System.IO
module MySqlConnector =
[<Literal>]
let ConnectionStringName = @"ProductionExtensionDB"
[<Literal>]
let ResolutionPath = __SOURCE_DIRECTORY__ + @"/../../packages/MySql.Data/lib/net452"
// create a type alias with the connection string and database vendor settings
type ExtensionDbProvider = SqlDataProvider<
DatabaseVendor = Common.DatabaseProviderTypes.MYSQL,
ConnectionStringName = ConnectionStringName,
ResolutionPath = ResolutionPath,
IndividualsAmount = 500,
UseOptionTypes = true >
type ExtensionDbType = ExtensionDbProvider.dataContext

View File

@ -20,7 +20,8 @@
#load "ExtensionDsLab.fsx"
open LogicalHacking.ExtensionDsLab
open LogicalHacking.ExtensionDsLab.Archive.SqlConnector
open LogicalHacking.ExtensionDsLab.Archive.MySqlConnector
open LogicalHacking.ExtensionDsLab.Archive.ExtensionCore
open Deedle
open FSharp.Data