Skip to content
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
77 changes: 0 additions & 77 deletions api/delete/delete_foos.yaml

This file was deleted.

27 changes: 0 additions & 27 deletions api/get/foo_by_id.dh

This file was deleted.

25 changes: 0 additions & 25 deletions api/get/search_foos.yaml

This file was deleted.

30 changes: 30 additions & 0 deletions api/pet/post.dh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#
# - experimental: recursive POST params
#

ENDPOINT
Adds a new pet to the store

POST /pet
BODY
id uint32
category {
id uint32
name string length[1,32]
}
name string length[1,32]
photo_urls [url]
tags {
id uint32
name string length[1,32]
}
status regex ^(available|pending|sold)$

# The framework returns the result of the last insert statement, in this case our 'pet'
# All inserts are part of the same transaction; boundaries can default to the whole of a 'label'
FIRST
upsert into category (id, name) values ({category.id}, {category.name});
upsert into tags (id, name) values ({tags.id}, {tags.name});

THEN RETURN RESULT FROM
insert into pets (id, name, photos_urls, status) values ({id}, {name}, {photosUrls}, {status});
33 changes: 33 additions & 0 deletions api/pet_entity.dh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
###################################################
# Describes a CRUD Entity mapped to a table
# Generates the following endpoints:
# - GET /pet/{primary key}
# - GET LIST /pet?{filter/search params}{pagination params}
# - POST /pet (create)
# - PUT /pet (upsert)
# - PATCH /pet (update)
# - DELETE /pet
#
# Caching (if "ON") uses "pets" as the cache key
# and caches results to /pets/{id},
# invalidating the cache on PUT and DELETE to that {id}

CRUD ENTITY /pets
MAPS TO TABLE pets
FIELDS
id uint32 pk
category uint32 fk(categories(id))
name string size [1,32]
photoUrls [url] mapsToField(photo_urls) optional
tags [string] size [1,32] fk(tags) optional
status string regex ^(available|pending|sold)$

CACHING IS ON

AUTHORIZING
GET BY ID to *
GET SEARCH to *
PUT to store_employee
POST to store_employee
PATCH to store_employee
DELETE to store_owner
26 changes: 26 additions & 0 deletions api/store/get_inventory.dh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
ENDPOINT gets the aggregated inventory
GET LIST /store/inventory
FROM
select status, count(status) as pets from pets group by status;

ENSURING
WITH CLEANUP
truncate pets;

it should not find results when table is empty
then
code 404

it should return expected results
given
insert into pets (name, status) values ('pet1', 'pending');
insert into pets (name, status) values ('pet2', 'available');
insert into pets (name, status) values ('pet3', 'sold');
insert into pets (name, status) values ('pet4', 'pending');
then
code 200
result
status pets
pending 2
available 1
sold 1
71 changes: 0 additions & 71 deletions database/migrations/1_initialize.dh

This file was deleted.

36 changes: 36 additions & 0 deletions migrations/1_initialize.dh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
MIGRATION initialize the database
UP
CREATE TABLE categories (
id serial PRIMARY KEY,
name varchar(32) not null
);

CREATE TYPE pet_status AS ENUM ('available', 'sold', 'pending');

CREATE TABLE pets (
id serial PRIMARY KEY,
category integer REFERENCES categories (id) NOT NULL,
name varchar(32) NOT NULL,
tags varchar(32)[] NOT NULL,
photo_urls varchar(256)[] NOT NULL,
status pet_status NOT NULL
);

CREATE TYPE order_status AS ENUM ('placed', 'approved', 'delivered');

CREATE TABLE orders (
id serial PRIMARY KEY,
pet_id integer REFERENCES pets (id) NOT NULL,
quantity integer NOT NULL,
ship_date timestamp with time zone NOT NULL,
status order_status NOT NULL,
complete boolean NOT NULL
);

DOWN
drop table categories;
drop table orders;
drop table pets;
drop type pet_status;
drop type order_status;

20 changes: 20 additions & 0 deletions migrations/2_something_else.dh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
MIGRATION setting up some tables
UP
CREATE TABLE categories (
id serial PRIMARY KEY,
name varchar(32) not null
);
DOWN
drop table categories;

ENSURING
it should test our clever assumptions
given
this thing right there
and that one, too
when
i do this really clever thing
then
col1 col2 `col 3`
1 `2 3` 4
a b c