<commit_before>﻿namespace Fss.Data

/// Postgres database wrapper.  Independent of other Fss pieces,
/// can be omitted along with System.Data and NPgsql dependencies for a smaller compilation unit
/// or used standalone from other Fss pieces.
/// Credit to <NAME> for the original dynamic operator concept 
open System.IO
open Npgsql
open System.Data

module Postgres = 

    type PgCustomizations() =  class
        interface Fss.Data.Common.Customization<NpgsqlParameter,NpgsqlConnection> with
            member x.sequenceMechanism() = Fss.Data.Common.RETURNS_CLAUSE
            member x.needsKeepAlive() = true

            member x.reloadTypes (conn:NpgsqlConnection) =
                conn.ReloadTypes()
            member x.reopenConnection(conn:NpgsqlConnection) = 
                NpgsqlConnection.ClearPool(conn)
            member x.getSearchPath(conn:NpgsqlConnection) =
                use command : NpgsqlCommand = conn.CreateCommand()
                command.CommandText <- "show search_path"
                let searchPath = command.ExecuteScalar( ) :?> string

                command.CommandText <- "select CURRENT_USER"
                let currentUser = command.ExecuteScalar() :?> string

                let schemas = searchPath.Split([|','|]) 
                                |> Array.map (fun s -> s.Trim())<commit_msg>BUG: keep alive for postgres reopening db was buggy<commit_after>﻿namespace Fss.Data

/// Postgres database wrapper.  Independent of other Fss pieces,
/// can be omitted along with System.Data and NPgsql dependencies for a smaller compilation unit
/// or used standalone from other Fss pieces.
/// Credit to <NAME> for the original dynamic operator concept 
open System.IO
open Npgsql
open System.Data

module Postgres = 

    type PgCustomizations() =  class
        interface Fss.Data.Common.Customization<NpgsqlParameter,NpgsqlConnection> with
            member x.sequenceMechanism() = Fss.Data.Common.RETURNS_CLAUSE
            member x.needsKeepAlive() = true

            member x.reloadTypes (conn:NpgsqlConnection) =
                conn.ReloadTypes()
            member x.reopenConnection(conn:NpgsqlConnection) = 
                try
                    if conn.State = ConnectionState.Closed then
                        conn.Open()
                with _ ->
                    ()
                    //NpgsqlConnection.ClearPool(conn)
            member x.getSearchPath(conn:NpgsqlConnection) =
                use command : NpgsqlCommand = conn.CreateCommand()
                command.CommandText <- "show search_path"
                let searchPath = command.ExecuteScalar( ) :?> string

                command.CommandText <- "select CURRENT_USER"
                let currentUser = command.ExecuteScalar() :?> string

                let schemas = searchPath.Split([|','|]) 
                                |> Array.map (fun s -> s.Trim())
{'fraction_non_alphanumeric': 0.08520179372197309, 'fraction_numerical': 0.0, 'mean_word_length': 2.118279569892473, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3276496', 'n_tokens_mistral': 794, 'n_tokens_neox': 738, 'n_words': 202}