FSharp.ObjectCatalogViews 1.0.3

dotnet add package FSharp.ObjectCatalogViews --version 1.0.3                
NuGet\Install-Package FSharp.ObjectCatalogViews -Version 1.0.3                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FSharp.ObjectCatalogViews" Version="1.0.3" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FSharp.ObjectCatalogViews --version 1.0.3                
#r "nuget: FSharp.ObjectCatalogViews, 1.0.3"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install FSharp.ObjectCatalogViews as a Cake Addin
#addin nuget:?package=FSharp.ObjectCatalogViews&version=1.0.3

// Install FSharp.ObjectCatalogViews as a Cake Tool
#tool nuget:?package=FSharp.ObjectCatalogViews&version=1.0.3                

FSharp.ObjectCatalogViews

将SQL数据库打印成F#记录类型。支持SqlServer数据库。可以从NuGet安装此包。

获取F#类型信息

根据数据库的类型,获取Type对象实例:

let is_nullable = true
let type_name = "float"
let ty = SqlTypeUtils.getType is_nullable type_name
Should.equal ty typeof<Nullable<float>>

获取数据库模式

获取数据库中所有表和视图的元数据。

let connstr = "Data Source=.;Integrated Security=True"
let db_name = "cook"
let schemas = TableMeta.getStructuralSchemas connstr db_name

sqlserver数据库包含若干个模式,每个模式包含若干个表或视图。我们可以从preceding code索引具体某个表的元数据。

let schema_name = "dbo"
let table_name = "book"
let table = schemas.[schema_name].[table_name]

获取数据库中的值

有了表的元数据,我们可以读取表:

let data:(string*Type*obj)[][] = TableMeta.readTable connstr db_name schema_name table

读取到的数据是一个交错数组,第一层表示数据有许多行,第二层表示每行有许多字段,元组的分量依次表示字段的名称,字段的类型,和字段的值。有了这些数据我们就可以利用反射将数据映射到更专用的类型中。

字段类型的映射规则:

  • 不可空的列,简单按照映射表映射。

  • 可为空的列,引用类型简单按照映射表映射。值类型映射为对应的Nullable<>类型。如:is null int 映射为Nullable<int>

字段返回值映射规则:

  • DBNull.Value映射为null

  • 其他按照映射表映射值。

应用于代码自动生成

The basic usage:

let code = ReadOnlyRecord.databaseDefinition connstr db_name

以上代码将会生成表字段组成的记录,并且有一个静态数组,装有数据库表内的所有数据。

有两个方法用于验证数据库文件是否过期:

SchemaValidTest用于验证记录类型定义是否与数据库一致。

DataValidTest用于验证静态数组是否与数据库中的数组一致。

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.3 474 3/16/2022
1.0.2 430 3/13/2021
1.0.1 363 3/4/2021
1.0.0 422 9/29/2020

update net 6