public void Execute_And_Drop_Text_Function_Test() { using var connection = new NpgsqlConnection(fixture.ConnectionString); var result = connection .Execute(@" create function test_func() returns text as $$ begin return 'I am function result!'; end $$ language plpgsql") .AsProcedure() .Single <string>("test_func"); Assert.Equal("I am function result!", result); connection.AsText().Execute("drop function test_func()"); var procMissing = false; try { connection.AsProcedure().Execute("test_func"); } catch (NpgsqlException) { procMissing = true; } Assert.True(procMissing); }
/// <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> /// <param name="pageSize">_page_size integer</param> /// <returns>ValueTask whose Result property is string</returns> public static async ValueTask <string> SearchCompaniesAsync(this NpgsqlConnection connection, string filter, int?page, int?pageSize) { return(await connection .AsProcedure() .ReadAsync <string>(Name, ("_filter", filter, NpgsqlDbType.Json), ("_page", page, NpgsqlDbType.Integer), ("_page_size", pageSize, NpgsqlDbType.Integer)) .SingleOrDefaultAsync()); }
/// <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> /// <param name="pageSize">_page_size integer</param> /// <returns>string</returns> public static string SearchCompanies(this NpgsqlConnection connection, string filter, int?page, int?pageSize) { return(connection .AsProcedure() .Read <string>(Name, ("_filter", filter, NpgsqlDbType.Json), ("_page", page, NpgsqlDbType.Integer), ("_page_size", pageSize, NpgsqlDbType.Integer)) .SingleOrDefault()); }
public void Array_Params_Test() { using var connection = new NpgsqlConnection(fixture.ConnectionString); connection .Execute(@" create function array_params_test(_p int[]) returns int[] as $$ begin return _p; end $$ language plpgsql"); var result = connection .AsProcedure() .Single <int[]>("array_params_test", ("_p", new[] { 3, 6, 9 })); Assert.Equal(new[] { 3, 6, 9 }, result); }