2017-08-07 07:43:50 +00:00
|
|
|
(*
|
|
|
|
* 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/>.
|
|
|
|
*)
|
|
|
|
|
2017-08-11 09:57:46 +00:00
|
|
|
namespace LogicalHacking.ExtensionDsLab.Archive
|
2017-08-07 07:43:50 +00:00
|
|
|
|
|
|
|
open FSharp.Data.Sql
|
2017-08-12 18:45:50 +00:00
|
|
|
open System.IO
|
2017-08-07 07:43:50 +00:00
|
|
|
|
|
|
|
module SqlConnector =
|
|
|
|
let [<Literal>] DevelopmentDB = "aa-ac.sqlite"
|
|
|
|
let [<Literal>] FullDB = "full.sqlite"
|
|
|
|
let [<Literal>] DatabaseDir = "archive/db"
|
|
|
|
// static (compile time) ConnectionString
|
2017-08-11 20:57:50 +00:00
|
|
|
let [<Literal>] ConnectionString = @"Data Source="
|
2017-08-12 18:22:32 +00:00
|
|
|
+ __SOURCE_DIRECTORY__
|
|
|
|
+ @"/../resources/extensions-schema.sqlite"
|
|
|
|
+ @";Version=3"
|
2017-08-07 07:43:50 +00:00
|
|
|
// create a type alias with the connection string and database vendor settings
|
2017-08-12 19:39:29 +00:00
|
|
|
type ExtensionDbProvider = SqlDataProvider<
|
|
|
|
ConnectionString = ConnectionString,
|
|
|
|
DatabaseVendor = Common.DatabaseProviderTypes.SQLITE,
|
|
|
|
// ResolutionPath = ResolutionPath,
|
|
|
|
IndividualsAmount = 500,
|
|
|
|
UseOptionTypes = true >
|
2017-08-11 12:52:03 +00:00
|
|
|
|
2017-08-12 19:39:29 +00:00
|
|
|
type ExtensionDbType = ExtensionDbProvider.dataContext
|
2017-08-12 19:26:47 +00:00
|
|
|
|
2017-08-12 19:39:29 +00:00
|
|
|
type Db = Dev | Prod | Auto | Custom of string
|
2017-08-11 12:52:03 +00:00
|
|
|
let rec getCtx dir = let archiveDir = function
|
2017-08-12 18:22:32 +00:00
|
|
|
| None -> __SOURCE_DIRECTORY__ + @"/../.."
|
2017-08-11 12:52:03 +00:00
|
|
|
| Some s -> s
|
|
|
|
function
|
2017-08-12 19:39:29 +00:00
|
|
|
| Dev -> ExtensionDbProvider.GetDataContext(sprintf "Data Source=%s/%s/%s;Version=3"
|
|
|
|
(archiveDir dir) DatabaseDir DevelopmentDB)
|
|
|
|
| Prod -> ExtensionDbProvider.GetDataContext(sprintf "Data Source=%s/%s/%s;Version=3"
|
|
|
|
(archiveDir dir) DatabaseDir FullDB)
|
|
|
|
| Custom db -> ExtensionDbProvider.GetDataContext(sprintf "Data Source=%s/%s/%s;Version=3"
|
|
|
|
(archiveDir dir) DatabaseDir db)
|
|
|
|
| Auto -> if File.Exists(sprintf "%s/%s/%s" (archiveDir dir) DatabaseDir FullDB) then
|
|
|
|
getCtx dir Prod
|
|
|
|
else
|
|
|
|
getCtx dir Dev
|
2017-08-12 19:26:47 +00:00
|
|
|
|
2017-08-12 19:39:29 +00:00
|
|
|
let getDownloads (ctx:ExtensionDbType) extid =
|
|
|
|
query {
|
2017-08-12 19:26:47 +00:00
|
|
|
for order in ctx.Main.Extension do
|
|
|
|
where (order.Extid = Some extid)
|
|
|
|
select (order.Date, order.Downloads)
|
|
|
|
} |> Seq.filter (fun (date, download) -> date.IsSome && download.IsSome)
|
|
|
|
|> Seq.map (fun (date, download) -> (System.DateTime.Parse(date.Value),
|
|
|
|
download.Value))
|
2017-08-13 13:08:57 +00:00
|
|
|
|> Seq.toArray
|
|
|
|
|
|
|
|
let getAllExtIds (ctx:ExtensionDbType) =
|
|
|
|
query {
|
|
|
|
for ext in ctx.Main.Extension do
|
|
|
|
select ext.Extid
|
|
|
|
} |> Seq.distinct
|
|
|
|
|> Seq.choose id
|
|
|
|
|> Seq.toList
|
|
|
|
|