All Projects → Zaid-Ajaj → DustyTables

Zaid-Ajaj / DustyTables

Licence: MIT license
Thin F# API for SqlClient for easy data access to ms sql server with functional seasoning on top

Programming Languages

F#
602 projects

Projects that are alternatives of or similar to DustyTables

loopback-connector-mssql
LoopBack connector for Microsoft SQL Server
Stars: ✭ 50 (-29.58%)
Mutual labels:  mssql
intake-sql
Plugin for Intake to read from SQL servers
Stars: ✭ 13 (-81.69%)
Mutual labels:  data-access
docker-workshop-with-react-aspnetcore-redis-rabbitmq-mssql
An Asp.Net Core Docker workshop project that includes react ui, redis, mssql, rabbitmq and azure pipelines
Stars: ✭ 53 (-25.35%)
Mutual labels:  mssql
TelephoneDirectory
microservices-> .net 6, golang - Docker, Ocelot, RabbitMq, MassTransit, mssql, postgresql, elasticsearch, kibana, jwt
Stars: ✭ 40 (-43.66%)
Mutual labels:  mssql
sqlserver
GORM sqlserver driver
Stars: ✭ 33 (-53.52%)
Mutual labels:  mssql
CodexMicroORM
An alternative to ORM's such as Entity Framework, offers light-weight database mapping to your existing CLR objects. Visit "Design Goals" on GitHub to see more rationale and guidance.
Stars: ✭ 32 (-54.93%)
Mutual labels:  data-access
oai
OAI-PMH R client
Stars: ✭ 13 (-81.69%)
Mutual labels:  data-access
database
Simple and easy go database micro framework
Stars: ✭ 12 (-83.1%)
Mutual labels:  mssql
qt-sql-example
Example Qt application that connects to SQL Server and displays a table from the database
Stars: ✭ 29 (-59.15%)
Mutual labels:  mssql
typetta
Node.js ORM written in TypeScript for type lovers.
Stars: ✭ 44 (-38.03%)
Mutual labels:  mssql
SqExpress
SqExpress is a sql query builder which allows creating SQL expressions directly in C# code with strong typing and intellisense.
Stars: ✭ 80 (+12.68%)
Mutual labels:  data-access
intake-esm
An intake plugin for parsing an Earth System Model (ESM) catalog and loading assets into xarray datasets.
Stars: ✭ 78 (+9.86%)
Mutual labels:  data-access
Akka.Persistence.SqlServer
Akka.Persistence.SqlServer provider
Stars: ✭ 53 (-25.35%)
Mutual labels:  mssql
sql-surveyor
High-level SQL parser. Identify tables, columns, aliases and more from your SQL script in one easy to consume object. Supports PostgreSQL, MySQL, SQL Server and Oracle (PL/SQL) dialects.
Stars: ✭ 19 (-73.24%)
Mutual labels:  mssql
database
Database Abstraction Layer, Schema Introspection, Schema Generation, Query Builders
Stars: ✭ 25 (-64.79%)
Mutual labels:  mssql
dbclient
데이터배이스 관리 / 자동 메일링 / Admin 자동화 / Database IDE Tool. SQL Development Helper. Support DBMS Oracle/Mysql/MS-SQL
Stars: ✭ 35 (-50.7%)
Mutual labels:  mssql
database connections
⚙️Demonstration code to connect R on MacOS to various database flavors.
Stars: ✭ 18 (-74.65%)
Mutual labels:  mssql
SQLServerTools
Инструменты обслуживания и разработки для Microsoft SQL Server, а также другие интересности
Stars: ✭ 147 (+107.04%)
Mutual labels:  mssql
xelogstash
Send SQL Server Extended Events to Logstash, Elastic Search, or JSON
Stars: ✭ 22 (-69.01%)
Mutual labels:  mssql
json-sql-builder2
Level Up Your SQL-Queries
Stars: ✭ 59 (-16.9%)
Mutual labels:  mssql

DustyTables Nuget

Functional wrapper around plain old (dusty?) SqlClient to simplify data access when talking to MS Sql Server databases.

Install

# nuget client
dotnet add package DustyTables

Query a table

open DustyTables

// get the connection from the environment
let connectionString() = Env.getVar "app_db"

type User = { Id: int; Username: string }

let getUsers() : User list =
    connectionString()
    |> Sql.connect
    |> Sql.query "SELECT * FROM dbo.[Users]"
    |> Sql.execute (fun read ->
        {
            Id = read.int "user_id"
            Username = read.string "username"
        })

Handle null values from table columns:

open DustyTables

// get the connection from the environment
let connectionString() = Env.getVar "app_db"

type User = { Id: int; Username: string; LastModified : Option<DateTime> }

let getUsers() : User list =
    connectionString()
    |> Sql.connect
    |> Sql.query "SELECT * FROM dbo.[users]"
    |> Sql.execute(fun read ->
        {
            Id = read.int "user_id"
            Username = read.string "username"
            // Notice here using `orNone` reader variants
            LastModified = read.dateTimeOrNone "last_modified"
        })

Providing default values for null columns:

open DustyTables

// get the connection from the environment
let connectionString() = Env.getVar "app_db"

type User = { Id: int; Username: string; Biography : string }

let getUsers() : User list =
    connectionString()
    |> Sql.connect
    |> Sql.query "select * from dbo.[users]"
    |> Sql.execute (fun read ->
        {
            Id = read.int "user_id";
            Username = read.string "username"
            Biography = defaultArg (read.stringOrNone "bio") ""
        })

Execute a parameterized query

open DustyTables

// get the connection from the environment
let connectionString() = Env.getVar "app_db"

// get product names by category
let productsByCategory (category: string) =
    connectionString()
    |> Sql.connect
    |> Sql.query "SELECT name FROM dbo.[Products] where category = @category"
    |> Sql.parameters [ "@category", Sql.string category ]
    |> Sql.execute (fun read -> read.string "name")

Executing a stored procedure with parameters

open DustyTables

// get the connection from the environment
let connectionString() = Env.getVar "app_db"

// check whether a user exists or not
let userExists (username: string) : bool =
    connectionString()
    |> Sql.connect
    |> Sql.storedProcedure "user_exists"
    |> Sql.parameters [ "@username", Sql.string username ]
    |> Sql.executeRow (fun read -> read.bool 0)

Executing a stored procedure with table-valued parameters

open DustyTables
open System.Data

// get the connection from the environment
let connectionString() = Env.getVar "app_db"

let executeMyStoredProcedure () : Async<int> =
    // create a table-valued parameter
    let customSqlTypeName = "MyCustomSqlTypeName"
    let dataTable = new DataTable()
    dataTable.Columns.Add "FirstName" |> ignore
    dataTable.Columns.Add "LastName"  |> ignore
    // add rows to the table parameter
    dataTable.Rows.Add("John", "Doe") |> ignore
    dataTable.Rows.Add("Jane", "Doe") |> ignore
    dataTable.Rows.Add("Fred", "Doe") |> ignore

    connectionString()
    |> Sql.connect
    |> Sql.storedProcedure "my_stored_proc"
    |> Sql.parameters
        [ "@foo", Sql.int 1
          "@people", Sql.table (customSqlTypeName, dataTable) ]
    |> Sql.executeNonQueryAsync

Building and running tests locally

You only need a working local SQL server. The tests will create databases when required and dispose them at the end of each test.

cd ./DustyTables.Build

# Build the solution
dotent run
# Run the tests
dotent run -- test
# Publish the nuget
dotnet run -- publish
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].