Carbunql.Postgres 0.0.4

dotnet add package Carbunql.Postgres --version 0.0.4                
NuGet\Install-Package Carbunql.Postgres -Version 0.0.4                
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="Carbunql.Postgres" Version="0.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Carbunql.Postgres --version 0.0.4                
#r "nuget: Carbunql.Postgres, 0.0.4"                
#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 Carbunql.Postgres as a Cake Addin
#addin nuget:?package=Carbunql.Postgres&version=0.0.4

// Install Carbunql.Postgres as a Cake Tool
#tool nuget:?package=Carbunql.Postgres&version=0.0.4                

Carbunql.Postgres

Carbunql.Postgres is a type-safe select query builder.

Note: This is an experimental library. Specifications are subject to significant changes.

Demo

Let's build a simple SQL statement using table joins and Where conditions. TypeSaleBuilding

Definition

Declare the table definition class.

public record struct table_a(int a_id, string text, int value);

public record struct table_b(int a_id, int b_id, string text, int value);

Buidling

Build the select query.

// Define an empty select query
SelectQuery sq = new SelectQuery();

// Specifies the table to select.
// Note: Make sure the SQL table alias name and variable name are the same
(FromClause from, table_a a) = sq.FromAs<table_a>("a");

// Write the table join expression.
// Combined expressions can be written in a type-safe manner.
// Note: Make sure that the join destination table alias name and return value variable name are the same.
table_b b = from.InnerJoinAs<table_b>(b => a.a_id == b.a_id);

// Describe the columns to select.
// If you want to get all columns, use the SelectAll method
sq.SelectAll(() => a);

// Use the Select method to select a specific column.
// You can also give it an alias using the As method.
sq.Select(() => b.b_id).As("table_b_key");

// A similar description can be made for the Where clause.
sq.Where(() => a.a_id == 1);

// Get SQL string
string sql = sq.ToCommand().CommandText;

Result

SELECT
    a.a_id,
    a.text,
    a.value,
    b.b_id AS table_b_key
FROM
    table_a AS a
    INNER JOIN table_b AS b ON a.a_id = b.a_id
WHERE
    (a.a_id = 1)

Features

  • You can write SQL using C# syntax.
  • No DBMS execution environment is required.
  • Can be used in conjunction with SQL parser library Carbunql.

Constraints

  • The generated SQL statements are assumed to be executed in Postgres.
  • Only select queries can be written.
  • Table definition classes must be handwritten.

Getting started

Preparing nuget package

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
0.0.4 265 11/17/2023
0.0.3 136 11/17/2023
0.0.2 147 11/14/2023
0.0.1 137 9/25/2023