@dbml/connector 5.0.0-alpha.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -475,8 +475,8 @@
475
475
  {
476
476
  "name": "status",
477
477
  "type": {
478
- "type_name": "chk_status_status",
479
- "schemaName": "dbo"
478
+ "type_name": "varchar(20)",
479
+ "schemaName": null
480
480
  },
481
481
  "dbdefault": {
482
482
  "type": "string",
@@ -1162,7 +1162,7 @@
1162
1162
  },
1163
1163
  "dbdefault": {
1164
1164
  "type": "string",
1165
- "value": "<Books>\r\n <Book>\r\n <Title>The Great Gatsby</Title>\r\n <Author>F. Scott Fitzgerald</Author>\r\n <Year>1925</Year>\r\n <Price>10.99</Price>\r\n <Publisher>Scribner</Publisher>\r\n <Location>New York</Location>\r\n <Genre>Fiction</Genre>\r\n <Subgenre>Classic</Subgenre>\r\n </Book>\r\n <Book>\r\n <Title>1984</Title>\r\n <Author>George Orwell</Author>\r\n <Year>1949</Year>\r\n <Price>8.99</Price>\r\n <Publisher>Secker & Warburg</Publisher>\r\n <Location>London</Location>\r\n <Genre>Dystopian</Genre>\r\n <Subgenre>Political Fiction</Subgenre>\r\n </Book>\r\n </Books>"
1165
+ "value": "<Books>\n <Book>\n <Title>The Great Gatsby</Title>\n <Author>F. Scott Fitzgerald</Author>\n <Year>1925</Year>\n <Price>10.99</Price>\n <Publisher>Scribner</Publisher>\n <Location>New York</Location>\n <Genre>Fiction</Genre>\n <Subgenre>Classic</Subgenre>\n </Book>\n <Book>\n <Title>1984</Title>\n <Author>George Orwell</Author>\n <Year>1949</Year>\n <Price>8.99</Price>\n <Publisher>Secker & Warburg</Publisher>\n <Location>London</Location>\n <Genre>Dystopian</Genre>\n <Subgenre>Political Fiction</Subgenre>\n </Book>\n </Books>"
1166
1166
  },
1167
1167
  "not_null": false,
1168
1168
  "increment": false,
@@ -1296,8 +1296,8 @@
1296
1296
  {
1297
1297
  "name": "gender",
1298
1298
  "type": {
1299
- "type_name": "chk_gender_gender",
1300
- "schemaName": "dbo"
1299
+ "type_name": "nvarchar(10)",
1300
+ "schemaName": null
1301
1301
  },
1302
1302
  "dbdefault": null,
1303
1303
  "not_null": false,
@@ -1541,8 +1541,8 @@
1541
1541
  {
1542
1542
  "name": "AddressID",
1543
1543
  "type": {
1544
- "type_name": "CK_Address_Valid_AddressID_AddressFormatID",
1545
- "schemaName": "dbo"
1544
+ "type_name": "uniqueidentifier(16)",
1545
+ "schemaName": null
1546
1546
  },
1547
1547
  "dbdefault": null,
1548
1548
  "not_null": true,
@@ -1554,8 +1554,8 @@
1554
1554
  {
1555
1555
  "name": "AddressFormatID",
1556
1556
  "type": {
1557
- "type_name": "CK_Address_Valid_AddressID_AddressFormatID",
1558
- "schemaName": "dbo"
1557
+ "type_name": "uniqueidentifier(16)",
1558
+ "schemaName": null
1559
1559
  },
1560
1560
  "dbdefault": null,
1561
1561
  "not_null": true,
@@ -1569,8 +1569,8 @@
1569
1569
  {
1570
1570
  "name": "A1",
1571
1571
  "type": {
1572
- "type_name": "CK_Address_Valid2_A1",
1573
- "schemaName": "dbo"
1572
+ "type_name": "uniqueidentifier(16)",
1573
+ "schemaName": null
1574
1574
  },
1575
1575
  "dbdefault": null,
1576
1576
  "not_null": true,
@@ -1582,8 +1582,8 @@
1582
1582
  {
1583
1583
  "name": "A2",
1584
1584
  "type": {
1585
- "type_name": "CK_Address_Valid2_A2_A3",
1586
- "schemaName": "dbo"
1585
+ "type_name": "uniqueidentifier(16)",
1586
+ "schemaName": null
1587
1587
  },
1588
1588
  "dbdefault": null,
1589
1589
  "not_null": true,
@@ -1595,8 +1595,8 @@
1595
1595
  {
1596
1596
  "name": "A3",
1597
1597
  "type": {
1598
- "type_name": "CK_Address_Valid2_A2_A3",
1599
- "schemaName": "dbo"
1598
+ "type_name": "uniqueidentifier(16)",
1599
+ "schemaName": null
1600
1600
  },
1601
1601
  "dbdefault": null,
1602
1602
  "not_null": true,
@@ -1608,8 +1608,8 @@
1608
1608
  {
1609
1609
  "name": "A4",
1610
1610
  "type": {
1611
- "type_name": "CK_Address_Valid2_A4",
1612
- "schemaName": "dbo"
1611
+ "type_name": "uniqueidentifier(16)",
1612
+ "schemaName": null
1613
1613
  },
1614
1614
  "dbdefault": null,
1615
1615
  "not_null": true,
@@ -1648,95 +1648,7 @@
1648
1648
  }
1649
1649
  ]
1650
1650
  },
1651
- "enums": [
1652
- {
1653
- "name": "chk_status_status",
1654
- "schemaName": "dbo",
1655
- "values": [
1656
- {
1657
- "name": "cancelled"
1658
- },
1659
- {
1660
- "name": "delivered"
1661
- },
1662
- {
1663
- "name": "shipped"
1664
- },
1665
- {
1666
- "name": "processing"
1667
- },
1668
- {
1669
- "name": "pending"
1670
- }
1671
- ]
1672
- },
1673
- {
1674
- "name": "chk_gender_gender",
1675
- "schemaName": "dbo",
1676
- "values": [
1677
- {
1678
- "name": "Other"
1679
- },
1680
- {
1681
- "name": "Female"
1682
- },
1683
- {
1684
- "name": "Male"
1685
- }
1686
- ]
1687
- },
1688
- {
1689
- "name": "CK_Address_Valid_AddressID_AddressFormatID",
1690
- "schemaName": "dbo",
1691
- "values": [
1692
- {
1693
- "name": "176029FA-D6D3-49E1-A48C-000000000002"
1694
- },
1695
- {
1696
- "name": "176029FA-D6D3-49E1-A48C-000000000001"
1697
- }
1698
- ]
1699
- },
1700
- {
1701
- "name": "CK_Address_Valid2_A1",
1702
- "schemaName": "dbo",
1703
- "values": [
1704
- {
1705
- "name": "333"
1706
- },
1707
- {
1708
- "name": "2222"
1709
- },
1710
- {
1711
- "name": "1111"
1712
- }
1713
- ]
1714
- },
1715
- {
1716
- "name": "CK_Address_Valid2_A2_A3",
1717
- "schemaName": "dbo",
1718
- "values": [
1719
- {
1720
- "name": "2222"
1721
- },
1722
- {
1723
- "name": "1111"
1724
- }
1725
- ]
1726
- },
1727
- {
1728
- "name": "CK_Address_Valid2_A4",
1729
- "schemaName": "dbo",
1730
- "values": [
1731
- {
1732
- "name": "3333"
1733
- },
1734
- {
1735
- "name": "2222"
1736
- }
1737
- ]
1738
- }
1739
- ],
1651
+ "enums": [],
1740
1652
  "refs": [
1741
1653
  {
1742
1654
  "name": "FK_AuthorNationality",
@@ -1941,100 +1853,222 @@
1941
1853
  "tableConstraints": {
1942
1854
  "dbo.Authors": {
1943
1855
  "AuthorID": {
1856
+ "checks": [],
1944
1857
  "pk": true
1945
1858
  },
1946
1859
  "NationalityID": {
1860
+ "checks": [],
1947
1861
  "pk": true
1948
1862
  },
1949
1863
  "AuthorName": {
1864
+ "checks": [],
1950
1865
  "unique": true
1951
1866
  },
1952
1867
  "BirthYear": {
1868
+ "checks": [],
1953
1869
  "unique": true
1954
1870
  }
1955
1871
  },
1956
1872
  "dbo.Books": {
1957
1873
  "BookID": {
1874
+ "checks": [],
1958
1875
  "pk": true
1959
1876
  },
1960
1877
  "AuthorID": {
1878
+ "checks": [],
1961
1879
  "pk": true
1962
1880
  },
1963
1881
  "ISBN": {
1882
+ "checks": [],
1964
1883
  "unique": true
1965
1884
  }
1966
1885
  },
1967
1886
  "dbo.DatetimeTypes": {
1968
1887
  "ID": {
1888
+ "checks": [],
1969
1889
  "pk": true
1970
1890
  }
1971
1891
  },
1972
1892
  "dbo.gender_reference": {
1973
1893
  "value": {
1894
+ "checks": [],
1974
1895
  "pk": true
1975
1896
  }
1976
1897
  },
1977
1898
  "dbo.NumberTypes": {
1978
1899
  "ID": {
1900
+ "checks": [],
1979
1901
  "pk": true
1980
1902
  }
1981
1903
  },
1982
1904
  "dbo.NumberTypesNoDefault": {
1983
1905
  "ID": {
1906
+ "checks": [],
1984
1907
  "pk": true
1985
1908
  }
1986
1909
  },
1987
1910
  "dbo.ObjectTypes": {
1988
1911
  "Id": {
1912
+ "checks": [],
1989
1913
  "pk": true
1990
1914
  }
1991
1915
  },
1992
1916
  "dbo.order_items": {
1993
1917
  "order_item_id": {
1918
+ "checks": [],
1994
1919
  "pk": true
1995
1920
  },
1996
1921
  "order_id": {
1922
+ "checks": [],
1997
1923
  "unique": true
1998
1924
  },
1999
1925
  "product_id": {
1926
+ "checks": [],
2000
1927
  "unique": true
1928
+ },
1929
+ "quantity": {
1930
+ "checks": [
1931
+ {
1932
+ "name": "chk_quantity_positive",
1933
+ "expression": "[quantity]>(0)"
1934
+ }
1935
+ ]
1936
+ },
1937
+ "unit_price": {
1938
+ "checks": [
1939
+ {
1940
+ "name": "chk_unit_price_positive",
1941
+ "expression": "[unit_price]>(0)"
1942
+ }
1943
+ ]
2001
1944
  }
2002
1945
  },
2003
1946
  "dbo.orders": {
2004
1947
  "order_id": {
1948
+ "checks": [],
2005
1949
  "pk": true
1950
+ },
1951
+ "total_amount": {
1952
+ "checks": [
1953
+ {
1954
+ "name": "chk_total_amount_positive",
1955
+ "expression": "[total_amount]>(0)"
1956
+ }
1957
+ ]
1958
+ },
1959
+ "status": {
1960
+ "checks": [
1961
+ {
1962
+ "name": "chk_status",
1963
+ "expression": "[status]='cancelled' OR [status]='delivered' OR [status]='shipped' OR [status]='processing' OR [status]='pending'"
1964
+ }
1965
+ ]
2006
1966
  }
2007
1967
  },
2008
1968
  "dbo.products": {
2009
1969
  "product_id": {
1970
+ "checks": [],
2010
1971
  "pk": true
1972
+ },
1973
+ "price": {
1974
+ "checks": [
1975
+ {
1976
+ "name": "chk_price_positive",
1977
+ "expression": "[price]>(0)"
1978
+ }
1979
+ ]
1980
+ },
1981
+ "stock_quantity": {
1982
+ "checks": [
1983
+ {
1984
+ "name": "chk_stock_non_negative",
1985
+ "expression": "[stock_quantity]>=(0)"
1986
+ }
1987
+ ]
2011
1988
  }
2012
1989
  },
2013
1990
  "dbo.StringTypes": {
2014
1991
  "Id": {
1992
+ "checks": [],
2015
1993
  "pk": true
2016
1994
  }
2017
1995
  },
2018
1996
  "dbo.table_with_comments": {
2019
1997
  "id": {
1998
+ "checks": [],
2020
1999
  "pk": true
2021
2000
  }
2022
2001
  },
2023
2002
  "dbo.user_define_data_types": {
2024
2003
  "id": {
2004
+ "checks": [],
2025
2005
  "pk": true
2006
+ },
2007
+ "gender": {
2008
+ "checks": [
2009
+ {
2010
+ "name": "chk_gender",
2011
+ "expression": "[gender]='Other' OR [gender]='Female' OR [gender]='Male'"
2012
+ }
2013
+ ]
2026
2014
  }
2027
2015
  },
2028
2016
  "dbo.users": {
2029
2017
  "user_id": {
2018
+ "checks": [],
2030
2019
  "pk": true
2031
2020
  },
2032
2021
  "email": {
2022
+ "checks": [
2023
+ {
2024
+ "name": "chk_email_format",
2025
+ "expression": "[email] like '%_@_%._%'"
2026
+ }
2027
+ ],
2033
2028
  "unique": true
2034
2029
  },
2035
2030
  "username": {
2031
+ "checks": [],
2036
2032
  "unique": true
2033
+ },
2034
+ "date_of_birth": {
2035
+ "checks": [
2036
+ {
2037
+ "name": "chk_age",
2038
+ "expression": "[date_of_birth]<=dateadd(year,(-13),getdate())"
2039
+ }
2040
+ ]
2041
+ }
2042
+ },
2043
+ "dbo.TestDescriptionTable": {
2044
+ "Name": {
2045
+ "checks": [
2046
+ {
2047
+ "name": "chk_name_len",
2048
+ "expression": "len([Name])>(6)"
2049
+ }
2050
+ ]
2037
2051
  }
2038
2052
  }
2053
+ },
2054
+ "checks": {
2055
+ "dbo.user_define_data_types": [
2056
+ {
2057
+ "name": "chk_age_range",
2058
+ "expression": "[age_start]<=[age_end]"
2059
+ }
2060
+ ],
2061
+ "dbo.AddressInfo": [
2062
+ {
2063
+ "name": "CK_Address_Valid",
2064
+ "expression": "([AddressID]='176029FA-D6D3-49E1-A48C-000000000002' OR [AddressID]='176029FA-D6D3-49E1-A48C-000000000001') AND ([AddressFormatID]='176029FA-D6D3-49E1-A48C-000000000002' OR [AddressFormatID]='176029FA-D6D3-49E1-A48C-000000000001')"
2065
+ }
2066
+ ],
2067
+ "dbo.AddressInfo2": [
2068
+ {
2069
+ "name": "CK_Address_Valid2",
2070
+ "expression": "([A1]='333' OR [A1]='2222' OR [A1]='1111') AND ([A2]='2222' OR [A2]='1111') AND ([A3]='1111' OR [A3]='2222') AND ([A4]='3333' OR [A4]='2222')"
2071
+ }
2072
+ ]
2039
2073
  }
2040
2074
  }
@@ -1344,47 +1344,87 @@
1344
1344
  "tableConstraints": {
1345
1345
  "categories": {
1346
1346
  "cat_id": {
1347
+ "checks": [],
1347
1348
  "pk": true
1348
1349
  }
1349
1350
  },
1350
1351
  "default_example": {
1351
1352
  "id": {
1353
+ "checks": [],
1352
1354
  "pk": true
1353
1355
  }
1354
1356
  },
1355
1357
  "hash_index_example": {
1356
1358
  "id": {
1359
+ "checks": [],
1357
1360
  "pk": true
1358
1361
  }
1359
1362
  },
1360
1363
  "index_example": {
1361
1364
  "email": {
1365
+ "checks": [],
1362
1366
  "unique": true
1363
1367
  },
1364
1368
  "id": {
1369
+ "checks": [],
1365
1370
  "pk": true
1366
1371
  }
1367
1372
  },
1368
1373
  "orders": {
1369
1374
  "order_id": {
1375
+ "checks": [],
1370
1376
  "pk": true
1371
1377
  }
1372
1378
  },
1373
1379
  "products": {
1374
1380
  "id": {
1381
+ "checks": [],
1375
1382
  "pk": true
1383
+ },
1384
+ "quantity": {
1385
+ "checks": [
1386
+ {
1387
+ "name": "max_quantity",
1388
+ "expression": "`quantity` < 10000"
1389
+ }
1390
+ ]
1391
+ },
1392
+ "total_value": {
1393
+ "checks": [
1394
+ {
1395
+ "name": "products_chk_2",
1396
+ "expression": "`total_value` > 0"
1397
+ }
1398
+ ]
1376
1399
  }
1377
1400
  },
1378
1401
  "users": {
1379
1402
  "email": {
1403
+ "checks": [],
1380
1404
  "unique": true
1381
1405
  },
1382
1406
  "user_id": {
1407
+ "checks": [],
1383
1408
  "pk": true
1384
1409
  },
1385
1410
  "username": {
1411
+ "checks": [],
1386
1412
  "unique": true
1387
1413
  }
1388
1414
  }
1415
+ },
1416
+ "checks": {
1417
+ "users": [
1418
+ {
1419
+ "name": "chk_last_login",
1420
+ "expression": "`created_at` <= `last_login`"
1421
+ }
1422
+ ],
1423
+ "products": [
1424
+ {
1425
+ "name": "products_chk_1",
1426
+ "expression": "(`price` > 0) and (`price` < 1000000)"
1427
+ }
1428
+ ]
1389
1429
  }
1390
1430
  }
@@ -1548,72 +1548,172 @@
1548
1548
  "tableConstraints": {
1549
1549
  "public.all_default_values": {
1550
1550
  "id": {
1551
+ "checks": [],
1551
1552
  "pk": true
1552
1553
  }
1553
1554
  },
1554
1555
  "public.books": {
1555
1556
  "bookid": {
1557
+ "checks": [],
1556
1558
  "pk": true
1557
1559
  },
1558
1560
  "isbn": {
1561
+ "checks": [],
1559
1562
  "unique": true
1560
1563
  }
1561
1564
  },
1562
1565
  "public.order_items": {
1563
1566
  "order_item_id": {
1567
+ "checks": [],
1564
1568
  "pk": true
1569
+ },
1570
+ "quantity": {
1571
+ "checks": [
1572
+ {
1573
+ "name": "chk_quantity_positive",
1574
+ "expression": "quantity > 0"
1575
+ }
1576
+ ]
1577
+ },
1578
+ "unit_price": {
1579
+ "checks": [
1580
+ {
1581
+ "name": "chk_unit_price_positive",
1582
+ "expression": "unit_price > (0)::numeric"
1583
+ }
1584
+ ]
1565
1585
  }
1566
1586
  },
1567
1587
  "public.orders": {
1568
1588
  "order_id": {
1589
+ "checks": [],
1569
1590
  "pk": true
1591
+ },
1592
+ "total_amount": {
1593
+ "checks": [
1594
+ {
1595
+ "name": "chk_total_amount_positive",
1596
+ "expression": "total_amount > (0)::numeric"
1597
+ }
1598
+ ]
1599
+ },
1600
+ "status": {
1601
+ "checks": [
1602
+ {
1603
+ "name": "chk_status",
1604
+ "expression": "(status)::text = ANY ((ARRAY['pending'::character varying, 'processing'::character varying, 'shipped'::character varying, 'delivered'::character varying, 'cancelled'::character varying])::text[])"
1605
+ }
1606
+ ]
1570
1607
  }
1571
1608
  },
1572
1609
  "public.products": {
1573
1610
  "product_id": {
1611
+ "checks": [],
1574
1612
  "pk": true
1613
+ },
1614
+ "price": {
1615
+ "checks": [
1616
+ {
1617
+ "name": "chk_price_positive",
1618
+ "expression": "price > (0)::numeric"
1619
+ }
1620
+ ]
1621
+ },
1622
+ "stock_quantity": {
1623
+ "checks": [
1624
+ {
1625
+ "name": "chk_stock_non_negative",
1626
+ "expression": "stock_quantity >= 0"
1627
+ }
1628
+ ]
1575
1629
  }
1576
1630
  },
1577
1631
  "public.table1": {
1578
1632
  "id": {
1633
+ "checks": [],
1579
1634
  "pk": true
1580
1635
  }
1581
1636
  },
1582
1637
  "dbml_test.table1": {
1583
1638
  "id": {
1639
+ "checks": [],
1584
1640
  "pk": true
1585
1641
  }
1586
1642
  },
1587
1643
  "public.table2": {
1588
1644
  "id": {
1645
+ "checks": [],
1589
1646
  "pk": true
1590
1647
  }
1591
1648
  },
1592
1649
  "dbml_test.table3": {
1593
1650
  "id": {
1651
+ "checks": [],
1594
1652
  "pk": true
1595
1653
  }
1596
1654
  },
1597
1655
  "public.table_with_comments": {
1598
1656
  "id": {
1657
+ "checks": [],
1599
1658
  "pk": true
1600
1659
  }
1601
1660
  },
1602
1661
  "public.user_define_data_types": {
1603
1662
  "id": {
1663
+ "checks": [],
1604
1664
  "pk": true
1665
+ },
1666
+ "height": {
1667
+ "checks": [
1668
+ {
1669
+ "name": "user_define_data_types_height_check",
1670
+ "expression": "height > (0)::double precision"
1671
+ }
1672
+ ]
1673
+ },
1674
+ "weight": {
1675
+ "checks": [
1676
+ {
1677
+ "name": "chk_positive_weight",
1678
+ "expression": "weight > (0)::double precision"
1679
+ }
1680
+ ]
1605
1681
  }
1606
1682
  },
1607
1683
  "public.users": {
1608
1684
  "user_id": {
1685
+ "checks": [],
1609
1686
  "pk": true
1610
1687
  },
1611
1688
  "email": {
1689
+ "checks": [
1690
+ {
1691
+ "name": "chk_email_format",
1692
+ "expression": "(email)::text ~* '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Z|a-z]{2,}$'::text"
1693
+ }
1694
+ ],
1612
1695
  "unique": true
1613
1696
  },
1614
1697
  "username": {
1698
+ "checks": [],
1615
1699
  "unique": true
1700
+ },
1701
+ "date_of_birth": {
1702
+ "checks": [
1703
+ {
1704
+ "name": "chk_age",
1705
+ "expression": "date_of_birth <= (CURRENT_DATE - '13 years'::interval)"
1706
+ }
1707
+ ]
1616
1708
  }
1617
1709
  }
1710
+ },
1711
+ "checks": {
1712
+ "public.products": [
1713
+ {
1714
+ "name": "chk_created_at",
1715
+ "expression": "created_at <= updated_at"
1716
+ }
1717
+ ]
1618
1718
  }
1619
1719
  }
@@ -209,7 +209,7 @@ async function generateTableConstraints(client, projectId, datasetId) {
209
209
  inlinePrimaryKeyMap[key] = {};
210
210
  }
211
211
  if (!inlinePrimaryKeyMap[key][columnNames]) {
212
- inlinePrimaryKeyMap[key][columnNames] = {};
212
+ inlinePrimaryKeyMap[key][columnNames] = { checks: [] };
213
213
  }
214
214
  inlinePrimaryKeyMap[key][columnNames].pk = true;
215
215
  });
@@ -266,6 +266,8 @@ async function fetchSchemaJsonByDataset(client, projectId, datasetId) {
266
266
  enums: [],
267
267
  indexes: (0, helpers_1.mergeIndexDictionary)(indexMap, compositePrimaryKeyMap),
268
268
  tableConstraints: inlinePrimaryKeyMap,
269
+ // Checks are not supported in BigQuery
270
+ checks: {},
269
271
  };
270
272
  }
271
273
  async function fetchSchemaJson(keyFilename) {
@@ -284,7 +286,7 @@ async function fetchSchemaJson(keyFilename) {
284
286
  acc.tableConstraints = (0, helpers_1.mergeTableConstraintDictionary)(acc.tableConstraints, tableConstraints);
285
287
  return acc;
286
288
  }, {
287
- tables: [], fields: {}, tableConstraints: {}, indexes: {}, refs: [], enums: [],
289
+ tables: [], fields: {}, tableConstraints: {}, indexes: {}, refs: [], enums: [], checks: {},
288
290
  });
289
291
  return res;
290
292
  }