diff --git a/api/methods.py b/api/methods.py index 747395b..22ceb89 100644 --- a/api/methods.py +++ b/api/methods.py @@ -7,6 +7,8 @@ SELECT id ,description FROM account_t + ORDER BY + description """, "params": () } @@ -42,6 +44,9 @@ SELECT ,iban ,account FROM tenant_t + ORDER BY + lastname + ,firstname """, "params": () } @@ -80,6 +85,8 @@ SELECT ,zip ,city FROM premise_t + ORDER BY + description """, "params": () } @@ -110,6 +117,9 @@ SELECT ,area ,flat_no FROM flat_t + ORDER BY + premise + ,description """, "params": () } @@ -140,6 +150,9 @@ SELECT ,startdate ,enddate FROM overhead_advance_t + ORDER BY + description + ,startdate """, "params": () } @@ -168,6 +181,9 @@ SELECT ,overhead_advance ,flat FROM overhead_advance_flat_mapping_t + ORDER BY + overhead_advance + ,flat """, "params": () } @@ -194,6 +210,9 @@ SELECT ,description ,premise FROM parking_t + ORDER BY + premise + ,description """, "params": () } @@ -220,6 +239,9 @@ SELECT ,description ,premise FROM commercial_premise_t + ORDER BY + premise + ,description """, "params": () } @@ -251,6 +273,9 @@ SELECT ,startdate ,enddate FROM tenancy_t + ORDER BY + description + ,startdate """, "params": () } @@ -285,6 +310,9 @@ SELECT ,startdate ,enddate FROM fee_t + ORDER BY + description + ,startdate """, "params": () } diff --git a/api/methods.py.tmpl b/api/methods.py.tmpl index c4c124d..0dcc5f5 100644 --- a/api/methods.py.tmpl +++ b/api/methods.py.tmpl @@ -10,6 +10,14 @@ SELECT ,$column.name #end for FROM ${table.name}_t +#if $table.selectors + ORDER BY +#set $sep = "" +#for $selector in $table.selectors + $sep$selector +#set $sep = "," +#end for +#end if """, "params": () } diff --git a/generate.py b/generate.py index fb9fb72..1884ce0 100644 --- a/generate.py +++ b/generate.py @@ -20,7 +20,8 @@ with open(args.schema) as schemaFile: schema = json.load(schemaFile) for table in schema["tables"]: - for column in table["columns"]: + columns = table["columns"] + for column in columns: if column["sqltype"] == 'serial': column["apitype"] = 'integer' column["jstype"] = 'number' @@ -39,6 +40,7 @@ for table in schema["tables"]: elif column["sqltype"].startswith('numeric'): column["apitype"] = 'number' column["jstype"] = 'number' + table["selectors"] = [ y["name"] for y in sorted([ x for x in columns if "selector" in x ], key=lambda x: x["selector"])] for f in glob.glob(args.template): print(f"process {f}") diff --git a/schema.json b/schema.json index 818aab1..7b9eb76 100644 --- a/schema.json +++ b/schema.json @@ -3,15 +3,15 @@ { "name": "account", "columns": [ - { "name": "description", "sqltype": "varchar(128)", "notnull": true } + { "name": "description", "sqltype": "varchar(128)", "notnull": true, "selector": 0 } ] }, { "name": "tenant", "columns": [ { "name": "salutation", "sqltype": "varchar(128)" }, - { "name": "firstname", "sqltype": "varchar(128)" }, - { "name": "lastname", "sqltype": "varchar(128)" }, + { "name": "firstname", "sqltype": "varchar(128)", "selector": 1 }, + { "name": "lastname", "sqltype": "varchar(128)", "selector": 0 }, { "name": "address1", "sqltype": "varchar(128)" }, { "name": "address2", "sqltype": "varchar(128)" }, { "name": "address3", "sqltype": "varchar(128)" }, @@ -26,7 +26,7 @@ { "name": "premise", "columns": [ - { "name": "description", "sqltype": "varchar(128)" }, + { "name": "description", "sqltype": "varchar(128)", "selector": 0 }, { "name": "street", "sqltype": "varchar(128)", "notnull": true }, { "name": "zip", "sqltype": "varchar(10)", "notnull": true }, { "name": "city", "sqltype": "varchar(128)", "notnull": true } @@ -35,8 +35,8 @@ { "name": "flat", "columns": [ - { "name": "description", "sqltype": "varchar(128)" }, - { "name": "premise", "sqltype": "integer", "foreignkey": true }, + { "name": "description", "sqltype": "varchar(128)", "selector": 1 }, + { "name": "premise", "sqltype": "integer", "foreignkey": true, "selector": 0 }, { "name": "area", "sqltype": "numeric(10,2)", "notnull": true }, { "name": "flat_no", "sqltype": "integer" } ] @@ -44,42 +44,42 @@ { "name": "overhead_advance", "columns": [ - { "name": "description", "sqltype": "varchar(128)" }, + { "name": "description", "sqltype": "varchar(128)", "selector": 0 }, { "name": "amount", "sqltype": "numeric(10,4)", "notnull": true }, - { "name": "startdate", "sqltype": "date" }, + { "name": "startdate", "sqltype": "date", "selector": 1 }, { "name": "enddate", "sqltype": "date" } ] }, { "name": "overhead_advance_flat_mapping", "columns": [ - { "name": "overhead_advance", "sqltype": "integer", "notnull": true, "foreignkey": true }, - { "name": "flat", "sqltype": "integer", "notnull": true, "foreignkey": true } + { "name": "overhead_advance", "sqltype": "integer", "notnull": true, "foreignkey": true, "selector": 0 }, + { "name": "flat", "sqltype": "integer", "notnull": true, "foreignkey": true, "selector": 1 } ] }, { "name": "parking", "columns": [ - { "name": "description", "sqltype": "varchar(128)" }, - { "name": "premise", "sqltype": "integer", "foreignkey": true } + { "name": "description", "sqltype": "varchar(128)", "selector": 1 }, + { "name": "premise", "sqltype": "integer", "foreignkey": true, "selector": 0 } ] }, { "name": "commercial_premise", "columns": [ - { "name": "description", "sqltype": "varchar(128)" }, - { "name": "premise", "sqltype": "integer", "foreignkey": true } + { "name": "description", "sqltype": "varchar(128)", "selector": 1 }, + { "name": "premise", "sqltype": "integer", "foreignkey": true, "selector": 0 } ] }, { "name": "tenancy", "columns": [ - { "name": "description", "sqltype": "varchar(128)" }, + { "name": "description", "sqltype": "varchar(128)", "selector": 0 }, { "name": "tenant", "sqltype": "integer", "notnull": true, "foreignkey": true }, { "name": "flat", "sqltype": "integer", "notnull": false, "foreignkey": true }, { "name": "parking", "sqltype": "integer", "notnull": false, "foreignkey": true }, { "name": "commercial_premise", "sqltype": "integer", "notnull": false, "foreignkey": true }, - { "name": "startdate", "sqltype": "date", "notnull": true }, + { "name": "startdate", "sqltype": "date", "notnull": true, "selector": 1 }, { "name": "enddate", "sqltype": "date", "notnull": false } ], "tableConstraints": [ @@ -89,10 +89,10 @@ { "name": "fee", "columns": [ - { "name": "description", "sqltype": "varchar(128)" }, + { "name": "description", "sqltype": "varchar(128)", "selector": 0 }, { "name": "amount", "sqltype": "numeric(10,2)", "notnull": true }, { "name": "fee_type", "sqltype": "varchar(10)", "notnull": true }, - { "name": "startdate", "sqltype": "date" }, + { "name": "startdate", "sqltype": "date", "selector": 1 }, { "name": "enddate", "sqltype": "date" } ], "tableConstraints": [