model.3.0.0.anubis 4.79 KB

read types/db_model.anubis

public define DB_Table   settings_table =
  db_table("settings",
    db_model(
      [
        db_column("id", p_key, []),
        db_column("var_name", char_field(20),  []),
        db_column("var_value", char_field(20),  []),
      ],
      "obj.var_name+\" = \"+obj.var_value"
    ),
    db_display(
      //list_view
      ["var_name", "var_value"],
      //list edit
      ["type"]
    )
  ).
  
public define DB_Table   production_memory_type_table =
  db_table("production_memory_type",
    db_model(
      [
        db_column("id", p_key, []),
        db_column("type", char_field(20),  []),  
      ],
      "to_String(obj.id)+\":\"+obj.type"
    ),
    db_display(
      //list_view
      ["id", "type"],
      //list edit
      ["type"]
    )
  ).

public define DB_Table   production_mass_storage_type_table =
  db_table("production_mass_storage_type",
    db_model(
      [
        db_column("id", p_key, []),
        db_column("type", char_field(20),  []),  
      ],
      "to_String(obj.id)+\":\"+obj.type"
    ),
    db_display(
      //list_view
      ["id", "type"],
      //list edit
      ["type"]
    )
  ).
  
public define DB_Table   production_mass_storage_model_table =
  db_table("production_mass_storage_model",
    db_model(
      [
        db_column("id", p_key, []),
        db_column("manufacturer",  char_field(20),   []),  
        db_column("type_id",       foreign_key("production_mass_storage_type"),   [indexed]),  
        db_column("capacity",      integer_field,   []),     // 
        db_column("tr_min",        integer_field,   []),     //  
        db_column("date_created",  datetime_field(auto_now_add),  []),
        db_column("last_modified", datetime_field(auto_now),  []),
        db_column("comments",      text_field,    [])      // whatever the user wants to keep
      ],
      "obj.manufacturer"
    ),
    db_display(
      //list_view
      ["id", "manufacturer", "type_id", "capacity", "tr_min", "last_modified", "date_created"],
      //list_edit
      []
    )
  ).
  
public define DB_Table   production_mass_storage_table =
  db_table("production_mass_storage",
    db_model(
      [
        db_column("id", p_key, []),
        db_column("purchase_id",   foreign_key("production_purchase"),   [indexed]),  
        db_column("model_id",      foreign_key("production_mass_storage_model"),   [indexed]),  
        db_column("serial",        char_field(40),   []),     // 
        db_column("status",        char_field(10),   []),     //  
        db_column("date_created",  datetime_field(auto_now_add),  []),
        db_column("last_modified", datetime_field(auto_now),  []),
        db_column("comments",      text_field,    [])      // whatever the user wants to keep
      ],
      "obj.purchase_id.string"
    ),
    db_display(
      //list_view
      ["model_id", "serial", "status", "date_created"],
      //list_edit
      ["purchase_id", "model_id", "serial", "status", "comments"]
    )
  ).
         
      "CREATE TABLE production_purchase (
        id            integer NOT NULL PRIMARY KEY,
        date          date NOT NULL,
        buyer_id      integer NOT NULL REFERENCES staff_staff (id),
        supplier_id   integer NOT NULL REFERENCES production_supplier (id),
        order_ref     varchar(50) NOT NULL,
        description   varchar(200) NOT NULL,
        date_created  datetime NOT NULL,
        last_modified datetime NOT NULL,
        comments      text NOT NULL
        )"
        
public define DB_Table   production_purchase_table =
  db_table("production_purchase",
    db_model(
      [
        db_column("id",            p_key,      []),
        db_column("date",          date_field(none),       []),         
        db_column("buyer_id",      foreign_key("staff_staff"),   [indexed]),  
        db_column("supplier_id",   foreign_key("production_supplier"),   [indexed]),  
        db_column("order_ref",     char_field(50),   []),     // 
        db_column("description",   char_field(200),  []),     // description of the purchase
        db_column("date_created",  datetime_field(auto_now_add),  []),
        db_column("last_modified", datetime_field(auto_now),  []),
        db_column("comments",     text_field,       []),     // whatever the user wants to keep 
      ],
      ""
    ),
    db_display(
      //list_view
      ["date", "supplier_id", "description"],
      //list_edit
      ["date", "buyer_id", "supplier_id", "order_ref", "description", "comments"]
    )
  ).
        
public define DB_Database
  the_database_description
  =
  db_database("prod_manager", 
            [
              settings_table,
              production_mass_storage_type_table,
              production_mass_storage_model_table,
              production_memory_type_table
              //production_mass_storage_table,
              //production_purchase_table
            ]).