Last active
February 25, 2019 09:16
-
-
Save kovid-rathee/0f4b93a81a6d4a6a23d51a54169c3c66 to your computer and use it in GitHub Desktop.
Sample transformation #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create type order_status as enum ( | |
'placed', | |
'accepted', | |
'cancelled_by_customer', | |
'cancelled_by_restaurant', | |
'delivered' | |
); | |
drop table if exists orders; | |
create table orders ( | |
id uuid primary key, | |
_serial_id serial, | |
order_items text[], | |
payment_response json, | |
order_status order_status, | |
order_location geometry(Point), | |
description text, | |
is_deleted boolean default false, | |
created_at timestamp without time zone default current_timestamp, | |
updated_at timestamp without time zone default current_timestamp | |
); | |
insert into orders (id, | |
order_items, | |
payment_response, | |
order_status, | |
order_location, | |
description) | |
values (uuid_generate_v4(), | |
array['Iced Tea','Naughty Lucy Burger','Large Fries'], | |
'{ | |
"id": "order_7IZKKI4Pnt2kEe", | |
"entity": "order", | |
"amount": 60000, | |
"currency": "INR", | |
"receipt": "rcptid33", | |
"status": "created", | |
"attempts": 0, | |
"notes": [], | |
"created_at": 1455696913}', | |
'placed', | |
ST_SetSRID(ST_MakePoint(71.31,24.24),4326), | |
'thisisarandom�character' | |
); | |
select id, | |
_serial_id, | |
array_to_json(order_items) order_items, | |
order_items[1] order_item_1, | |
order_items[2] order_item_1, | |
order_items[3] order_item_1, | |
order_status, | |
transformation_utils.remove_invalid_characters(description) description, | |
payment_response payment_response, | |
(payment_response->'id') payment_response_id, | |
(payment_response->'entity') payment_response_entity, | |
(payment_response->'amount') payment_response_amount, | |
(payment_response->'currency') payment_response_currency, | |
(payment_response->'receipt') payment_response_receipt, | |
(payment_response->'status') payment_response_status, | |
(payment_response->'notes') payment_response_notes, | |
(payment_response->'attempts') payment_response_attempts, | |
(payment_response->'created_at') payment_response_created_at, | |
ST_X(order_location) order_location_latitude, | |
ST_Y(order_location) order_location_longitude, | |
order_location, | |
transformation_utils.ts_to_isodate(created_at) created_at_date, | |
transformation_utils.ts_to_seconds_of_day(created_at) created_at_time, | |
created_at, | |
transformation_utils.ts_to_isodate(updated_at) updated_at_date, | |
transformation_utils.ts_to_seconds_of_day(updated_at) updated_at_time, | |
updated_at | |
from orders; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment