++ed by:

2 non-PAUSE users.

Al Newkirk

NAME

Doodle::Grammar::Postgres

ABSTRACT

Doodle Grammar For PostgreSQL

SYNOPSIS

  use Doodle::Grammar::Postgres;

  my $self = Doodle::Grammar::Postgres->new;

DESCRIPTION

This provide determines how command classes should be interpreted to produce the correct DDL statements for Postgres.

INHERITS

This package inherits behaviors from:

Doodle::Grammar

LIBRARIES

This package uses type constraints from:

Doodle::Library

METHODS

This package implements the following methods:

create_column

  create_column(Command $command) : Str

Returns the SQL statement for the create column command.

create_column example #1
  # given: synopsis

  use Doodle;

  my $d = Doodle->new;
  my $t = $d->table('users');
  my $c = $t->primary('id');

  my $command = $c->create;

  $self->create_column($command);

  # alter table "users" add column "id" serial primary key

create_index

  create_index(Command $command) : Str

Returns the SQL statement for the create index command.

create_index example #1
  # given: synopsis

  use Doodle;

  my $d = Doodle->new;
  my $t = $d->table('users');
  my $i = $t->index(columns => ['id']);

  my $command = $i->create;

  $self->create_index($command);

  # create index "indx_users_id" on "users" ("id")

create_relation

  create_relation(Command $command) : Str

Returns the SQL statement for the create relation command.

create_relation example #1
  # given: synopsis

  use Doodle;

  my $d = Doodle->new;
  my $t = $d->table('users');
  my $r = $t->relation('profile_id', 'profiles', 'id');

  my $command = $r->create;

  $self->create_relation($command);

  # alter table "users" add constraint "fkey_users_profile_id_profiles_id"
  # foreign key ("profile_id") references "profiles" ("id")

create_schema

  create_schema(Command $command) : Str

Returns the SQL statement for the create schema command.

create_schema example #1
  # given: synopsis

  use Doodle;

  my $d = Doodle->new;
  my $s = $d->schema('app');

  my $command = $s->create;

  $self->create_schema($command);

  # create database "app"

create_table

  create_table(Command $command) : Str

Returns the SQL statement for the create table command.

create_table example #1
  # given: synopsis

  use Doodle;

  my $d = Doodle->new;
  my $t = $d->table('users');
  my $c = $t->column('data');

  my $command = $t->create;

  $self->create_table($command);

  # create table "users" ("data" varchar(255))

delete_column

  delete_column(Command $command) : Str

Returns the SQL statement for the delete column command.

delete_column example #1
  # given: synopsis

  use Doodle;

  my $d = Doodle->new;
  my $t = $d->table('users');
  my $c = $t->primary('id');

  my $command = $c->delete;

  $self->delete_column($command);

  # alter table "users" drop column "id"

delete_index

  delete_index(Command $command) : Str

Returns the SQL statement for the delete index command.

delete_index example #1
  # given: synopsis

  use Doodle;

  my $d = Doodle->new;
  my $t = $d->table('users');
  my $i = $t->index(columns => ['id']);

  my $command = $i->delete;

  $self->delete_index($command);

  # drop index "indx_users_id"

delete_relation

  delete_relation(Command $command) : Str

Returns the SQL statement for the delete relation command.

delete_relation example #1
  # given: synopsis

  use Doodle;

  my $d = Doodle->new;
  my $t = $d->table('users');
  my $r = $t->relation('profile_id', 'profiles', 'id');

  my $command = $r->delete;

  $self->delete_relation($command);

  # alter table "users" drop constraint "fkey_users_profile_id_profiles_id"

delete_schema

  delete_schema(Command $command) : Str

Returns the SQL statement for the create schema command.

delete_schema example #1
  # given: synopsis

  use Doodle;

  my $d = Doodle->new;
  my $s = $d->schema('app');

  my $command = $s->create;

  $self->delete_schema($command);

  # drop database "app"

delete_table

  delete_table(Command $command) : Str

Returns the SQL statement for the delete table command.

delete_table example #1
  # given: synopsis

  use Doodle;

  my $d = Doodle->new;
  my $t = $d->table('users');
  my $c = $t->column('data');

  my $command = $t->delete;

  $self->delete_table($command);

  # drop table "users"

rename_column

  rename_column(Command $command) : Str

Returns the SQL statement for the rename column command.

rename_column example #1
  # given: synopsis

  use Doodle;

  my $d = Doodle->new;
  my $t = $d->table('users');
  my $c = $t->primary('id');

  my $command = $c->rename('uid');

  $self->rename_column($command);

  # alter table "users" rename column "id" to "uid"

rename_table

  rename_table(Command $command) : Str

Returns the SQL statement for the rename table command.

rename_table example #1
  # given: synopsis

  use Doodle;

  my $d = Doodle->new;
  my $t = $d->table('users');
  my $c = $t->column('data');

  my $command = $t->rename('people');

  $self->rename_table($command);

  # alter table "users" rename to "people"

type_binary

  type_binary(Column $column) : Str

Returns the type expression for a binary column.

type_binary example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('binary');

  $self->type_binary($column);

  # bytea

type_boolean

  type_boolean(Column $column) : Str

Returns the type expression for a boolean column.

type_boolean example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('boolean');

  $self->type_boolean($column);

  # boolean

type_char

  type_char(Column $column) : Str

Returns the type expression for a char column.

type_char example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('char');

  $self->type_char($column);

  # char(1)
type_char example #2
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('char', size => 10);

  $self->type_char($column);

  # char(10)

type_date

  type_date(Column $column) : Str

Returns the type expression for a date column.

type_date example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('date');

  $self->type_date($column);

  # date

type_datetime

  type_datetime(Column $column) : Str

Returns the type expression for a datetime column.

type_datetime example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('datetime');

  $self->type_datetime($column);

  # timestamp(0) without time zone

type_datetime_tz

  type_datetime_tz(Column $column) : Str

Returns the type expression for a datetime_tz column.

type_datetime_tz example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('datetime_tz');

  $self->type_datetime_tz($column);

  # timestamp(0) with time zone

type_decimal

  type_decimal(Column $column) : Str

Returns the type expression for a decimal column.

type_decimal example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('decimal');

  $self->type_decimal($column);

  # decimal(5, 2)

type_double

  type_double(Column $column) : Str

Returns the type expression for a double column.

type_double example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('double');

  $self->type_double($column);

  # double precision

type_enum

  type_enum(Column $column) : Str

Returns the type expression for a enum column.

type_enum example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('enum', options => [
    1, "one", 2, '{"two": 2}', "3", "'three'"
  ]);

  $self->type_enum($column);

  # varchar(225) check ("enum" in (1, 'one', 2, '{"two": 2}', 3, '\'three\''))

type_float

  type_float(Column $column) : Str

Returns the type expression for a float column.

type_float example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('float');

  $self->type_float($column);

  # double precision

type_integer

  type_integer(Column $column) : Str

Returns the type expression for a integer column.

type_integer example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('integer');

  $self->type_integer($column);

  # integer

type_integer_big

  type_integer_big(Column $column) : Str

Returns the type expression for a integer_big column.

type_integer_big example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('integer_big');

  $self->type_integer_big($column);

  # bigint

type_integer_big_unsigned

  type_integer_big_unsigned(Column $column) : Str

Returns the type expression for a integer_big_unsigned column.

type_integer_big_unsigned example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('integer_big_unsigned');

  $self->type_integer_big_unsigned($column);

  # bigint

type_integer_medium

  type_integer_medium(Column $column) : Str

Returns the type expression for a integer_medium column.

type_integer_medium example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('integer_medium');

  $self->type_integer_medium($column);

  # integer

type_integer_medium_unsigned

  type_integer_medium_unsigned(Column $column) : Str

Returns the type expression for a integer_medium_unsigned column.

type_integer_medium_unsigned example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('integer_medium_unsigned');

  $self->type_integer_medium_unsigned($column);

  # integer

type_integer_small

  type_integer_small(Column $column) : Str

Returns the type expression for a integer_small column.

type_integer_small example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('integer_small');

  $self->type_integer_small($column);

  # smallint

type_integer_small_unsigned

  type_integer_small_unsigned(Column $column) : Str

Returns the type expression for a integer_small_unsigned column.

type_integer_small_unsigned example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('integer_small_unsigned');

  $self->type_integer_small_unsigned($column);

  # smallint

type_integer_tiny

  type_integer_tiny(Column $column) : Str

Returns the type expression for a integer_tiny column.

type_integer_tiny example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('integer_tiny');

  $self->type_integer_tiny($column);

  # smallint

type_integer_tiny_unsigned

  type_integer_tiny_unsigned(Column $column) : Str

Returns the type expression for a integer_tiny_unsigned column.

type_integer_tiny_unsigned example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('integer_tiny_unsigned');

  $self->type_integer_tiny_unsigned($column);

  # smallint

type_integer_unsigned

  type_integer_unsigned(Column $column) : Str

Returns the type expression for a integer_unsigned column.

type_integer_unsigned example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('integer_unsigned');

  $self->type_integer_unsigned($column);

  # integer

type_json

  type_json(Column $column) : Str

Returns the type expression for a json column.

type_json example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('json');

  $self->type_json($column);

  # json

type_string

  type_string(Column $column) : Str

Returns the type expression for a string column.

type_string example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('string');

  $self->type_string($column);

  # varchar(255)

type_text

  type_text(Column $column) : Str

Returns the type expression for a text column.

type_text example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('text');

  $self->type_text($column);

  # text

type_text_long

  type_text_long(Column $column) : Str

Returns the type expression for a text_long column.

type_text_long example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('text_long');

  $self->type_text_long($column);

  # text

type_text_medium

  type_text_medium(Column $column) : Str

Returns the type expression for a text_medium column.

type_text_medium example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('text_medium');

  $self->type_text_medium($column);

  # text

type_time

  type_time(Column $column) : Str

Returns the type expression for a time column.

type_time example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('time');

  $self->type_time($column);

  # time(0) without time zone

type_time_tz

  type_time_tz(Column $column) : Str

Returns the type expression for a time_tz column.

type_time_tz example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('time_tz');

  $self->type_time_tz($column);

  # time(0) with time zone

type_timestamp

  type_timestamp(Column $column) : Str

Returns the type expression for a timestamp column.

type_timestamp example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('timestamp');

  $self->type_timestamp($column);

  # timestamp(0) without time zone

type_timestamp_tz

  type_timestamp_tz(Column $column) : Str

Returns the type expression for a timestamp_tz column.

type_timestamp_tz example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('timestamp_tz');

  $self->type_timestamp_tz($column);

  # timestamp(0) with time zone

type_uuid

  type_uuid(Column $column) : Str

Returns the type expression for a uuid column.

type_uuid example #1
  # given: synopsis

  use Doodle;

  my $ddl = Doodle->new;
  my $column = $ddl->table('users')->column('uuid');

  $self->type_uuid($column);

  # uuid

update_column

  update_column(Command $command) : Str

Returns the SQL statement for the update column command.

update_column example #1
  # given: synopsis

  use Doodle;

  my $d = Doodle->new;
  my $t = $d->table('users');
  my $c = $t->primary('id');

  my $command = $c->update;

  $self->update_column($command);

  # alter table [users] alter column [id] type integer

  $command = $c->update(set => 'not null');

  $self->update_column($command);

  # alter table [users] alter column [id] set not null

wrap

  wrap(Str $arg) : Str

Returns a wrapped SQL identifier.

wrap example #1
  # given: synopsis

  my $wrapped = $self->wrap('data');

  # "data"

AUTHOR

Al Newkirk, awncorp@cpan.org

LICENSE

Copyright (C) 2011-2019, Al Newkirk, et al.

This is free software; you can redistribute it and/or modify it under the terms of the The Apache License, Version 2.0, as elucidated in the "license file".

PROJECT

Wiki

Project

Initiatives

Milestones

Contributing

Issues