Skip to content

Instantly share code, notes, and snippets.

View vbilopav's full-sized avatar
🏠
Working from home

Vedran Bilopavlović vbilopav

🏠
Working from home
View GitHub Profile

Dictionary for database example

  • Server: PostgreSQL 216.158.72.53:5432, version 13.7 (Debian 13.7-0+deb11u1)
  • Local time stamp: 2022-07-20T12:41:43.0051958+02:00
  • Schema: public

Table of Contents

@vbilopav
vbilopav / md_table_to_table_table.sql
Last active July 17, 2023 12:37
Script to create a postgresql table from markdown table (pasted as variable)
do
$$
declare
_table_name text = 'md_temp';
_md text = '
| Command | Description |
| --- | --- |
| `git status` | List all *new or modified* files |
| `git diff` | Show file differences that **havent been** staged |
';
/*
Task: get a set of movies where Zendaya played a role,
and for every such movie calculate the average review score,
and also retrieve the list of top 5 actors in the order of credits.
Here’s how such query can be written in EdgeQL:
select
Movie {
title,
select
title,
name,
avg(score)
from movies m
join movies_actors using(movie_id)
join actors a using(actor_id)
join (
select movie_id
from actors join movies_actors using(actor_id)
@vbilopav
vbilopav / duplicate_foreign_keys.sql
Last active June 12, 2023 08:57
Detect all duplicate foreign keys from public schema and generates a script that drops all duplicates but first.
--
-- Detect all duplicate foreign keys from public schema and generates a script that drops all duplicates but first.
--
with fkeys as (
select
tc.constraint_name,
tc.table_name,
kcu.column_name,
ccu.table_name as foreign_table_name,
@vbilopav
vbilopav / JsonValidator.cs
Last active May 23, 2023 11:11
Utility function in C# which validates JSON string against .NET model type by using Newtonsoft Json library.
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
namespace MyNamespace;
public static class JsonValidator
{
public static bool IsJsonValidType(this string json, Type modelType, out string? message)
{
try
/*
Creates TypeScript models from CSharp models
- TypeScript model is set by config key TsModelsPath
- CSharp models namespace is set by config key ModelNamespace
1) Add to your Program.cs:
if (ModelBuilder.Build(args))
{
return;
}
create or replace function companies.search_companies(
_search varchar,
_skip integer,
_take integer
)
returns json
language plpgsql
as $$
declare
_count bigint;
@vbilopav
vbilopav / database-dict-sample.md
Created July 22, 2022 09:45
Sample of database dictionary

Dictionary for database pdd

  • Server: PostgreSQL localhost:5436, version 14.0
  • Local time stamp: 2022-07-15T12:01:44.0784710+02:00
  • Schema: public

Table of Contents