Sklep w trzech tabelach
Pięćdziesięciu klientów, ich zamówienia i pozycje każdego zamówienia. O liczbie wierszy decydują relacje, a każde dziecko niesie klucz rodzica.
en-US 3 tabele 478 wierszy JSON
belongs_to: { customer: 0-5 } daje każdemu klientowi do pięciu zamówień, niektórym żadnego, a belongs_to: { order: 1-4 } daje każdemu zamówieniu od jednej do czterech pozycji. W JSON-ie każde zamówienie stoi wewnątrz swojego klienta, a każda pozycja wewnątrz swojego zamówienia, i mimo to każde nazywa rodzica w osobnym polu.
Statusy, plany i ilości pochodzą z list w przepisie, więc to wartości, które twoja aplikacja zna. Sumy i ceny są liczbami dziesiętnymi, a mniej więcej siedem kuponów na dziesięć jest pustych, żeby pokazać, jak twój kod traktuje brak wartości. Zmień format: json na csv, a dostaniesz osobny plik na każdą tabelę.
Przepis
# A shop in three related tables: customers, their orders and the lines of each
# order, written as one JSON file with every order inside its customer and every
# line inside its order.
#
# Every customer has zero to five orders and every order one to four lines, so
# the number of rows comes from the relations rather than from a count. Each
# child also carries the key of its parent. Plans, statuses and quantities come
# from lists, totals and prices are decimal numbers, and about seven coupons in
# ten are left empty.
#
# qadg generate orders.yaml
#
# writes dataset.json and run-note.json. The same seed gives the same rows on
# every machine.
version: "0.1"
seed: "orders"
locale: en-US
entities:
customer:
count: 50
primary_key: [customer_id]
fields:
customer_id: { type: integer, unique: true }
first_name: { generator: first_name, required: true, max_length: 40 }
last_name: { generator: last_name, required: true, max_length: 40 }
gender: { generator: gender }
plan: { values: [free, pro, team] }
city: { generator: city }
state: { generator: region }
zip: { generator: postal_code }
consistency:
- first_name matches: [gender]
order:
belongs_to: { customer: 0-5 }
primary_key: [order_id]
fields:
order_id: { type: integer, unique: true }
status: { values: [new, paid, shipped, cancelled] }
total: { type: decimal }
card: { generator: card }
coupon: { values: [SPRING10, WELCOME, FREESHIP], empty: 70% }
order_line:
belongs_to: { order: 1-4 }
primary_key: [line_id]
fields:
line_id: { type: integer, unique: true }
isbn: { generator: isbn }
quantity: { values: ["1", "2", "3", "4", "5"] }
price: { type: decimal }
output:
format: json
Uruchomienie
Zapisz przepis i w tym samym folderze uruchom to polecenie. Niżej jest to, co program przy nim wypisał.
$ qadg generate orders.yaml customer: 50 rows, 8 columns order: 120 rows, 5 columns order_line: 308 rows, 4 columns customer: state follows city, though no rule says so customer: zip follows city and state, though no rule says so 3 tables, 478 rows written
Co zapisuje
dataset.json
Pierwsze 40 z 3 960 linii.
{
"customer": [
{
"customer_id": "351940",
"first_name": "Claudia",
"last_name": "Russell",
"gender": "female",
"plan": "pro",
"city": "Winston-Salem",
"state": "NC",
"zip": "27103",
"order": [
]
},
{
"customer_id": "743231",
"first_name": "Taylor",
"last_name": "Mejia",
"gender": "female",
"plan": "team",
"city": "Plains",
"state": "KS",
"zip": "67869",
"order": [
]
},
{
"customer_id": "386830",
"first_name": "Desiree",
"last_name": "Orr",
"gender": "female",
"plan": "team",
"city": "Miami",
"state": "FL",
"zip": "33136",
"order": [
{
"order_id": "35172",
"status": "new",
"total": "359.60",
run-note.json
Seed, locale i wersje, z którymi ruszył przebieg, oraz każda zapisana tabela z liczbą wierszy i kolumn.