Skip to content

Commit

Permalink
Update pgroutiner
Browse files Browse the repository at this point in the history
  • Loading branch information
vbilopav committed Apr 23, 2021
1 parent 1edc37b commit 9bbc457
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 145 deletions.
2 changes: 1 addition & 1 deletion CompaniesWebBlazor/Client/Pages/CompanyModal.razor
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
private async Task Delete()
{
logger.LogInformation("Deleting company {0}: {1}", company.Id, company.Name);
await Http.PostAsJsonAsync<Company>("/companies/delete", company);
await Http.PostAsJsonAsync<dynamic>($"/companies/delete/{company.Id}", new { });
await Close();
await OnUpdate.InvokeAsync();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace CompaniesDb.Extensions
{
public static class CompanyDelete
public static class CompanyDeleteBy
{
public const string Name = "companies";

Expand All @@ -20,27 +20,27 @@ DELETE FROM ""companies""
""id"" = @id";

/// <summary>
/// Delete record of table ""companies"" by matching values of key fields: id
/// Delete record of table ""companies"" by primary keys.
/// </summary>
/// <param name="model">Instance of a "CompaniesDb.Extensions.Company" model class.</param>
public static void DeleteCompany(this NpgsqlConnection connection, Company model)
/// <param name="id">Select table ""companies"" where field id bigint is this value.</param>
public static void DeleteCompanyById(this NpgsqlConnection connection, long id)
{
connection
.Prepared()
.Execute(Sql,
("id", model.Id, NpgsqlDbType.Bigint));
("id", id, NpgsqlDbType.Bigint));
}

/// <summary>
/// Delete record of table ""companies"" by matching values of key fields: id
/// Asynchronously delete record of table ""companies"" by primary keys.
/// </summary>
/// <param name="model">Instance of a "CompaniesDb.Extensions.Company" model class.</param>
public static async ValueTask DeleteCompanyAsync(this NpgsqlConnection connection, Company model)
/// <param name="id">Select table ""companies"" where field id bigint is this value.</param>
public static async void DeleteCompanyByIdAsync(this NpgsqlConnection connection, long id)
{
await connection
.Prepared()
.ExecuteAsync(Sql,
("id", model.Id, NpgsqlDbType.Bigint));
("id", id, NpgsqlDbType.Bigint));
}
}
}
4 changes: 0 additions & 4 deletions CompaniesWebBlazor/CompaniesDb/Extensions/SearchCompanies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ public static class PgRoutineSearchCompanies

/// <summary>
/// Executes plpgsql function "search_companies"
///
/// Search companies by filter and return data page with results.
/// Parameters:
/// - `_filter` is `json` with following schema `{"search", "areaId"}`
/// - `page` page indexed from 1
/// - `page_size`, default is 25
/// Returning json schema:
/// `{"count", "page": {"id", "name", "website", "area", "about", "modified"}}`
///
/// </summary>
/// <param name="filter">_filter json</param>
/// <param name="page">_page integer</param>
Expand All @@ -42,15 +40,13 @@ public static string SearchCompanies(this NpgsqlConnection connection, string fi

/// <summary>
/// Asynchronously executes plpgsql function "search_companies"
///
/// Search companies by filter and return data page with results.
/// Parameters:
/// - `_filter` is `json` with following schema `{"search", "areaId"}`
/// - `page` page indexed from 1
/// - `page_size`, default is 25
/// Returning json schema:
/// `{"count", "page": {"id", "name", "website", "area", "about", "modified"}}`
///
/// </summary>
/// <param name="filter">_filter json</param>
/// <param name="page">_page integer</param>
Expand Down
146 changes: 73 additions & 73 deletions CompaniesWebBlazor/CompaniesDb/README.md
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
# Dictionary for database `companies_web_demo`

- Server: PostgreSQL `localhost:5434`, version `12.0`
- Local time stamp: `2021-04-22T11:07:55.6727599+02:00`
- Schema: public

## Table of Contents

- Table [`public.companies`](#table-publiccompanies)
- Table [`public.company_areas`](#table-publiccompany_areas)
- Function [`public.search_companies(json, integer, integer)`](#function-publicsearch_companiesjson-integer-integer)
## Tables

### Table `public.companies`

<!-- comment on table "public"."companies" is @until-end-tag; -->
Main table for compnaies data.
<!-- end -->

| Column | | Type | Nullable | Default | Comment |
| ------ | ----------- | -----| -------- | ------- | ------- |
| <a id="user-content-public-companies-id" href="#public-companies-id">#</a>`id` | **PK** | `bigint` | **NO** | *auto increment* | <!-- comment on column "public"."companies"."id" is @until-end-tag; --><!-- end --> |
| <a id="user-content-public-companies-name" href="#public-companies-name">#</a>`name` | | `character varying(256)` | **NO** | | <!-- comment on column "public"."companies"."name" is @until-end-tag; --><!-- end --> |
| <a id="user-content-public-companies-name_normalized" href="#public-companies-name_normalized">#</a>`name_normalized` | **IDX** | `character varying(256)` | **NO** | | <!-- comment on column "public"."companies"."name_normalized" is @until-end-tag; -->Company name in lowercase uniquely indexed. Search is on this field.<!-- end --> |
| <a id="user-content-public-companies-website" href="#public-companies-website">#</a>`website` | | `character varying(1024)` | **NO** | | <!-- comment on column "public"."companies"."website" is @until-end-tag; --><!-- end --> |
| <a id="user-content-public-companies-area_id" href="#public-companies-area_id">#</a>`area_id` | **FK [](#public-company_areas-id) `company_areas.id`** | `integer` | **NO** | | <!-- comment on column "public"."companies"."area_id" is @until-end-tag; --><!-- end --> |
| <a id="user-content-public-companies-about" href="#public-companies-about">#</a>`about` | | `character varying` | YES | | <!-- comment on column "public"."companies"."about" is @until-end-tag; --><!-- end --> |
| <a id="user-content-public-companies-modified" href="#public-companies-modified">#</a>`modified` | | `timestamp without time zone` | **NO** | `timezone('utc'::text, now())` | <!-- comment on column "public"."companies"."modified" is @until-end-tag; --><!-- end --> |

<a href="#table-of-contents" title="Table of Contents">&#8673;</a>

### Table `public.company_areas`

<!-- comment on table "public"."company_areas" is @until-end-tag; -->
List of all possible company areas.
<!-- end -->

| Column | | Type | Nullable | Default | Comment |
| ------ | ----------- | -----| -------- | ------- | ------- |
| <a id="user-content-public-company_areas-id" href="#public-company_areas-id">#</a>`id` | **PK** | `integer` | **NO** | *auto increment* | <!-- comment on column "public"."company_areas"."id" is @until-end-tag; --><!-- end --> |
| <a id="user-content-public-company_areas-name" href="#public-company_areas-name">#</a>`name` | | `character varying(256)` | **NO** | | <!-- comment on column "public"."company_areas"."name" is @until-end-tag; --><!-- end --> |

<a href="#table-of-contents" title="Table of Contents">&#8673;</a>

## Routines

### Function `public.search_companies(json, integer, integer)`

- Returns `json`

- Language is `plpgsql`

<!-- comment on function "public"."search_companies"(json, integer, integer) is @until-end-tag; -->


Search companies by filter and return data page with results.

Parameters:

- `_filter` is `json` with following schema `{"search", "areaId"}`

- `page` page indexed from 1

- `page_size`, default is 25

Returning json schema:

`{"count", "page": {"id", "name", "website", "area", "about", "modified"}}`


<!-- end -->

<a href="#table-of-contents" title="Table of Contents">&#8673;</a>
# Dictionary for database `companies_web_demo`

- Server: PostgreSQL `localhost:5434`, version `12.0`
- Local time stamp: `2021-04-23T13:26:22.7402337+02:00`
- Schema: public

## Table of Contents

- Table [`public.companies`](#table-publiccompanies)
- Table [`public.company_areas`](#table-publiccompany_areas)
- Function [`public.search_companies(json, integer, integer)`](#function-publicsearch_companiesjson-integer-integer)
## Tables

### Table `public.companies`

<!-- comment on table "public"."companies" is @until-end-tag; -->
Main table for compnaies data.
<!-- end -->

| Column | | Type | Nullable | Default | Comment |
| ------ | ----------- | -----| -------- | ------- | ------- |
| <a id="user-content-public-companies-id" href="#public-companies-id">#</a>`id` | **PK** | `bigint` | **NO** | *auto increment* | <!-- comment on column "public"."companies"."id" is @until-end-tag; --><!-- end --> |
| <a id="user-content-public-companies-name" href="#public-companies-name">#</a>`name` | | `character varying(256)` | **NO** | | <!-- comment on column "public"."companies"."name" is @until-end-tag; --><!-- end --> |
| <a id="user-content-public-companies-name_normalized" href="#public-companies-name_normalized">#</a>`name_normalized` | **IDX** | `character varying(256)` | **NO** | | <!-- comment on column "public"."companies"."name_normalized" is @until-end-tag; -->Company name in lowercase uniquely indexed. Search is on this field.<!-- end --> |
| <a id="user-content-public-companies-website" href="#public-companies-website">#</a>`website` | | `character varying(1024)` | **NO** | | <!-- comment on column "public"."companies"."website" is @until-end-tag; --><!-- end --> |
| <a id="user-content-public-companies-area_id" href="#public-companies-area_id">#</a>`area_id` | **FK [](#public-company_areas-id) `company_areas.id`** | `integer` | **NO** | | <!-- comment on column "public"."companies"."area_id" is @until-end-tag; --><!-- end --> |
| <a id="user-content-public-companies-about" href="#public-companies-about">#</a>`about` | | `character varying` | YES | | <!-- comment on column "public"."companies"."about" is @until-end-tag; --><!-- end --> |
| <a id="user-content-public-companies-modified" href="#public-companies-modified">#</a>`modified` | | `timestamp without time zone` | **NO** | `timezone('utc'::text, now())` | <!-- comment on column "public"."companies"."modified" is @until-end-tag; --><!-- end --> |

<a href="#table-of-contents" title="Table of Contents">&#8673;</a>

### Table `public.company_areas`

<!-- comment on table "public"."company_areas" is @until-end-tag; -->
List of all possible company areas.
<!-- end -->

| Column | | Type | Nullable | Default | Comment |
| ------ | ----------- | -----| -------- | ------- | ------- |
| <a id="user-content-public-company_areas-id" href="#public-company_areas-id">#</a>`id` | **PK** | `integer` | **NO** | *auto increment* | <!-- comment on column "public"."company_areas"."id" is @until-end-tag; --><!-- end --> |
| <a id="user-content-public-company_areas-name" href="#public-company_areas-name">#</a>`name` | | `character varying(256)` | **NO** | | <!-- comment on column "public"."company_areas"."name" is @until-end-tag; --><!-- end --> |

<a href="#table-of-contents" title="Table of Contents">&#8673;</a>

## Routines

### Function `public.search_companies(json, integer, integer)`

- Returns `json`

- Language is `plpgsql`

<!-- comment on function "public"."search_companies"(json, integer, integer) is @until-end-tag; -->

Search companies by filter and return data page with results.

Parameters:

- `_filter` is `json` with following schema `{"search", "areaId"}`

- `page` page indexed from 1

- `page_size`, default is 25

Returning json schema:

`{"count", "page": {"id", "name", "website", "area", "about", "modified"}}`


<!-- end -->

<a href="#table-of-contents" title="Table of Contents">&#8673;</a>
Expand Down
4 changes: 2 additions & 2 deletions CompaniesWebBlazor/CompaniesDb/Scripts/Data.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DO $CompaniesDb_data$
DO $CompaniesWebDb_data$
BEGIN
--
-- PostgreSQL database dump
Expand Down Expand Up @@ -35,5 +35,5 @@ PERFORM pg_catalog.setval('public.company_areas_id_seq', 10, true);
--
-- PostgreSQL database dump complete
--
END $CompaniesDb_data$
END $CompaniesWebDb_data$
LANGUAGE plpgsql;
4 changes: 2 additions & 2 deletions CompaniesWebBlazor/CompaniesDb/Scripts/Schema.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DO $CompaniesDb_schema$
DO $CompaniesWebDb_schema$
BEGIN
--
-- PostgreSQL database dump
Expand Down Expand Up @@ -180,5 +180,5 @@ ALTER TABLE ONLY public.companies
--
-- PostgreSQL database dump complete
--
END $CompaniesDb_schema$
END $CompaniesWebDb_schema$
LANGUAGE plpgsql;
19 changes: 12 additions & 7 deletions CompaniesWebBlazor/CompaniesDb/appsettings.PgRoutiner.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* PgRoutiner (3.3.2.0) settings */
/* PgRoutiner (3.3.8.0) settings */
{
/* see https://github.com/vb-consulting/PgRoutiner/wiki/10.-WORKING-WITH-CONNECTIONS for more info */
"ConnectionStrings": {
"CompaniesDb": "postgresql://postgres:postgres@localhost:5434/companies_web_demo"
//"Connection1": "Server={server};Db={database};Port={port};User Id={user};Password={password};"
//"Connection2": "postgresql://{user}:{password}@{server}:{port}/{database}"
},
Expand All @@ -17,15 +16,16 @@
- Use "-d" or "--dump" switch to redirect all outputs to the command line.
- For more info see: https://github.com/vb-consulting/PgRoutiner/wiki/1.-WORKING-WITH-SETTINGS#general-settings
*/
"Connection": "CompaniesDb",
"SkipConnectionPrompt": false,
"Connection": "CompaniesWebDb",
"SkipConnectionPrompt": true,
"Schema": null,
"Execute": null,
"Dump": false,
"SkipIfExists": [],
"SkipUpdateReferences": false,
"PgDump": "pg_dump",
"PgDumpFallback": "C:\\Program Files\\PostgreSQL\\{0}\\bin\\pg_dump.exe",
"ConfigPath": "../Server/appsettings.Development.json",

/*
Code generation general settings. Used in:
Expand Down Expand Up @@ -69,7 +69,10 @@
"float4": "float",
"int4": "int"
},
"CustomModels": { "Companies": "Company", "CompanyAreas": "CompanyArea" },
"CustomModels": {
"Companies": "Company",
"CompanyAreas": "CompanyArea"
},
"ModelDir": "../Shared",
"ModelCustomNamespace": "CompaniesWebBlazor.Shared",
"EmptyModelDir": false,
Expand Down Expand Up @@ -230,7 +233,9 @@
"CrudReadAll": [ "company_areas" ],
"CrudUpdate": [],
"CrudUpdateReturning": [],
"CrudDelete": [ "companies" ],
"CrudDeleteReturning": []
"CrudDelete": [ ],
"CrudDeleteReturning": [],
"CrudDeleteBy": [ "companies" ],
"CrudDeleteByReturning": []
}
}
32 changes: 32 additions & 0 deletions CompaniesWebBlazor/CompaniesDbTests/DeleteCompanyByIdUnitTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// <auto-generated />
using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xunit;
using Norm;
using FluentAssertions;
using CompaniesDb.Extensions;
using CompaniesWebBlazor.Shared;

namespace CompaniesDbTests
{
public class DeleteCompanyByIdUnitTests : PostgreSqlUnitTestFixture
{
public DeleteCompanyByIdUnitTests(PostgreSqlFixture fixture) : base(fixture) { }

[Fact]
public void DeleteCompanyById_Test1()
{
// Arrange
var model = Connection.CreateCompanyOnConflictDoUpdateReturning(new Company { Name = "n", NameNormalized = "nn", About = "about", AreaId = 1, Website = "website" });
long id = model.Id;

// Act
Connection.DeleteCompanyById(id);

// Assert
Assert.Null(Connection.ReadCompanyById(id));
}
}
}
32 changes: 0 additions & 32 deletions CompaniesWebBlazor/CompaniesDbTests/DeleteCompanyUnitTests.cs

This file was deleted.

Loading

0 comments on commit 9bbc457

Please sign in to comment.