@cran/psql.lodash

0.0.5 • Public • Published

Postgres Lodash

Lodash Functionality for Postgres

exception

select _.catch($$ select 1 $$);
-- (,,,,,,,,,)

select * from _.catch($$ select dne $$);
-- returned_sqlstate    | 42703
-- column_name          |
-- constraint_name      |
-- pg_datatype_name     |
-- message_text         | column "dne" does not exist
-- table_name           |
-- schema_name          |
-- pg_exception_detail  |
-- pg_exception_hint    |
-- pg_exception_context | PL/pgSQL function _.catch(text) line 13 at EXECUTE

text

camel

select _.camel('this-is_a TEST/123');
-- thisIsATest123

constant

select _.constant('this-is_a TEST/123');
-- THIS_IS_A_TEST_123

contains

select _.contains('this-is_a TEST/123', 'this');
-- t
select _.contains('this-is_a TEST/123', 'that');
-- f

ends

select _.ends('this-is_a TEST/123', '123');
-- t
select _.ends('this-is_a TEST/123', '456');
-- f

join

select _.join(array[1, 2, 3], '.');
-- 1.2.3
select _.join(array['a', 'b', 'c'], '.');
-- a.b.c

kebab

select _.kebab('this-is_a TEST/123');
-- this-is-a-test-123

pascal

select _.pascal('this-is_a TEST/123');
-- ThisIsATest123

snake

select _.snake('this-is_a TEST/123');
-- this_is_a_test_123

starts

select _.starts('this-is_a TEST/123', 'this');
-- t
select _.starts('this-is_a TEST/123', 'that');
-- f

text

This should not be used in place of ::text. Its primary use is for when immutability is required, for instance, in generated always as statements

create temp table test (
  id uuid generated always as (
    uuid_generate_v5(
      uuid_ns_dns(), id_uuid::text||id_date::text
    )
  ) stored,
  id_uuid uuid default uuid_generate_v4(),
  id_date date default current_date
);
-- ERROR:  generation expression is not immutable
create temp table test (
  id uuid generated always as (
    uuid_generate_v5(
      uuid_ns_dns(), _.text(id_uuid)||_.text(id_date)
    )
  ) stored,
  id_uuid uuid default uuid_generate_v4(),
  id_date date default current_date
);
-- CREATE TABLE

words

select _.words('this-is_a TEST/123');
-- {this,is,a,TEST,123}

Readme

Keywords

Package Sidebar

Install

npm i @cran/psql.lodash

Weekly Downloads

1

Version

0.0.5

License

CC-BY-ND-4.0

Unpacked Size

7.25 kB

Total Files

18

Last publish

Collaborators

  • common-cranberry