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
@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

CREATE EXTENSION pg_stat_statements SCHEMA public;
# postgresql.conf
shared_preload_libraries = 'pg_stat_statements' # (change requires restart)
pg_stat_statements.max = 10000
pg_stat_statements.track = all
select
g.code
from (
select generate_series as code from generate_series(1000, 9999)
) g
left outer join tbl t on g.code = t.id
where
t.id is null
order by
random() limit 1;
select
keys.key, data->>keys.key as value
from (
select distinct jsonb_object_keys(data) as key from table
) keys cross join table
where data->>keys.key is not null
group by keys.key, data->>keys.key
select "value" from "values" where id = @id;
do $$
begin
drop function if exists select_company_and_sectors(int);
drop function if exists update_company(int, json);
drop function if exists update_sectors(json);
drop table if exists employees;
drop table if exists sectors;
drop table if exists companies;
define(["sys/html"], html => {
const
test = (object, extensions) => {
extensions.forEach(e => {
if (object.prototype[e] !== undefined) {
throw new Error(`Error: Name collision - object ${object} already have defined "${e}" !`);
}
});
};
@vbilopav
vbilopav / pubsub.js
Last active February 19, 2019 14:26
/*
*** Publish/Subscribe global events functions - implementation of pubsub pattern for loose coupled components ***
Usage:
* Publish global application event:
publish("unique event name / category / subcategory", arg1, arg2, arg3);
or
select
t.table_name,
c.column_name,
c.data_type ||
case when c.character_maximum_length is not null
then '(' || cast(c.character_maximum_length as varchar) || ')'
else case when c.numeric_precision is not null
then '(' || cast(c.numeric_precision as varchar) || ',' || cast(c.numeric_precision_radix as varchar) || ')'
|| case when coalesce(c.numeric_scale, 0) = 0 then '' else ',' || cast(c.numeric_scale as varchar) || ')' end