Skip to content

Commit bb786ce

Browse files
committed
refactoring - getting rid of datatable constructors mess
1 parent 09f5eea commit bb786ce

File tree

4 files changed

+11
-14
lines changed

4 files changed

+11
-14
lines changed

src/SqlClient/DataTable.fs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,28 @@ open FSharp.Data.SqlClient
88

99
[<Sealed>]
1010
[<CompilerMessageAttribute("This API supports the FSharp.Data.SqlClient infrastructure and is not intended to be used directly from your code.", 101, IsHidden = true)>]
11-
type DataTable<'T when 'T :> DataRow> private (tableName, knownSelectCommand, getDesignTimeConnection:Lazy<_>) =
12-
inherit DataTable(tableName)
11+
type DataTable<'T when 'T :> DataRow> (knownSelectCommandOrDesignTimeInfo) =
12+
inherit DataTable(match knownSelectCommandOrDesignTimeInfo with | Choice1Of2 (tableName, _) -> tableName | _ -> null)
1313

14+
let tableName = base.TableName
1415
let rows = base.Rows
1516
let getSelectCommand maybeRuntimeConnection maybeRuntimeTransaction =
1617
let makeSelectCommand connection =
1718
let selectCommand = new SqlCommand("SELECT * FROM " + tableName)
1819
selectCommand.Connection <- connection
1920
selectCommand
2021

21-
if Option.isSome knownSelectCommand
22-
then
23-
knownSelectCommand.Value
24-
else
22+
match knownSelectCommandOrDesignTimeInfo with
23+
| Choice1Of2 (_, (getDesignTimeConnection:Lazy<_>)) ->
2524
match maybeRuntimeTransaction, maybeRuntimeConnection with
2625
| Some (tran:SqlTransaction), _ ->
2726
let command = makeSelectCommand tran.Connection
2827
command.Transaction <- tran
2928
command
3029
| None, Some connection ->
31-
makeSelectCommand connection
30+
makeSelectCommand connection
3231
| _ -> makeSelectCommand (getDesignTimeConnection.Value)
33-
34-
new (tableName, getDesignTimeConnection) = new DataTable<'T>(tableName, None, getDesignTimeConnection)
35-
new (createCommand) = new DataTable<'T>(null, Some createCommand, lazy(createCommand.Connection))
32+
| Choice2Of2 knownSelectCommand -> knownSelectCommand
3633

3734
member __.Rows : IList<'T> = {
3835
new IList<'T> with

src/SqlClient/ISqlCommand.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,14 @@ type ``ISqlCommand Implementation``(cfg: DesignTimeConfig, connection: Connectio
227227

228228
static member internal ExecuteDataTable(cmd, getReaderBehavior, parameters, expectedDataReaderColumns) =
229229
use cursor = ``ISqlCommand Implementation``.ExecuteReader(cmd, getReaderBehavior, parameters, expectedDataReaderColumns)
230-
let result = new FSharp.Data.DataTable<DataRow>(cmd)
230+
let result = new FSharp.Data.DataTable<DataRow>(Choice2Of2 cmd)
231231
result.Load(cursor)
232232
result
233233

234234
static member internal AsyncExecuteDataTable(cmd, getReaderBehavior, parameters, expectedDataReaderColumns) =
235235
async {
236236
use! reader = ``ISqlCommand Implementation``.AsyncExecuteReader(cmd, getReaderBehavior, parameters, expectedDataReaderColumns)
237-
let result = new FSharp.Data.DataTable<DataRow>(cmd)
237+
let result = new FSharp.Data.DataTable<DataRow>(Choice2Of2 cmd)
238238
result.Load(reader)
239239
return result
240240
}

src/SqlClient/SqlClient.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
<Compile Include="SqlCommandProvider.fs" />
8585
<Compile Include="SqlClientProvider.fs" />
8686
<Compile Include="SqlEnumProvider.fs" />
87-
<Compile Include="Scripts\Scratchpad.fsx" />
87+
<None Include="Scripts\Scratchpad.fsx" />
8888
<None Include="Scripts\XE.fsx" />
8989
<None Include="packages.config" />
9090
</ItemGroup>

src/SqlClient/SqlClientProvider.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ type public SqlProgrammabilityProvider(config : TypeProviderConfig) as this =
372372

373373
let connection = lazy
374374
new SqlConnection( %%connectionString.RunTimeValueExpr(config.IsHostedExecution))
375-
let table = new DataTable<DataRow>(twoPartTableName, connection)
375+
let table = new DataTable<DataRow>(Choice1Of2( twoPartTableName, connection))
376376

377377
let primaryKey = ResizeArray()
378378
for line in serializedSchema.Split('\n') do

0 commit comments

Comments
 (0)