List all fields of all mysql db tables in yUML Class Diagrams


This script doesn’t work any more: it’s in maintenance mode.

This script (see usage) will list all fields of all tables of a mysql db (postgress coming soon or you can easily adapt) and convert them to yUML classes.


For example, you can generate these classes from a Wordpress Database:

;ask db-parameters
either value? 'mysql-db [
   ans: ask rejoin ["mysql-db" " (by default " mysql-db ")" ": "]
   if ans <> "" [mysql-db: ans]
][
   mysql-db: ask "mysql-db: "
]

do code-block/2
do code-block/3
do code-block/4
do code-block/5

;mysql protocol is automatically loaded with askuml script so you don't need to
;otherwise see http://softinnov.org/rebol/mysql.shtml
mysql-connect: rejoin [mysql:// mysql-login ":" mysql-password "@" mysql-server "/" mysql-db]

  tables-list: read/custom mysql-connect ["SHOW TABLES;"]
  final-result0: copy []
  final-result1: copy ""
  final-result: copy ""
  foreach table-block tables-list [
      table: pick table-block 1
      append final-result0 get-list-fields table
      append final-result0 newline
      append final-result convert-to-yuml table
      append final-result newline
      append final-result1 convert-to-yuml-usecase table
      append final-result1 newline
  ]
  write clipboard://  final-result
either exists? it: %askuml/db-params.txt [
    params-block: copy load it
][
    params-block: []
]

either res: find params-block mysql-db [
    mysql-server: pick res 2
    mysql-login: pick res 3
    mysql-password: pick res 4
    print [ mysql-db "found in" it]
][

    new-param: reduce [
    mold mysql-db
    mold mysql-server
    mold mysql-login
    mold mysql-password
    ]

    either not exists? %askuml/db-params.txt [
        create-dir "askuml/"
        write/append %askuml/db-params.txt reform new-param
    ][
        write/append %askuml/db-params.txt reform [newline new-param]
    ]

]
get-list-fields: func[table][
  Print ["list all fields of " table]
  sql: copy []
  append sql rejoin ["describe " table ";"]
  Probe fields-list: read/custom mysql-connect sql
  clipboard: copy ""
  append clipboard mold table
  append clipboard " ["
  append clipboard newline
  foreach field-block fields-list [
      append clipboard mold pick field-block 1
      append clipboard " ["
      append clipboard mold pick field-block 2
      append clipboard " "
      append clipboard mold pick field-block 3
      append clipboard " "
      append clipboard mold pick field-block 4
      append clipboard " "
      append clipboard mold pick field-block 5
      append clipboard " "
      append clipboard mold pick field-block 6
      append clipboard "]"
      append clipboard newline
  ]
  append clipboard "]"
  return-value: copy clipboard
]
convert-to-yuml: func[table][
      clipboard: copy ""
      append clipboard rejoin ["[" table "|"]
      foreach field fields-list [
          field1: pick field 1
          append clipboard field1
          append clipboard ";"
      ]
      append clipboard {]}
      clipboard
]
convert-to-yuml-usecase: func[table][
      clipboard: copy ""
      append clipboard rejoin ["{" table newline]
      foreach field fields-list [
          field1: pick field 1
          append clipboard rejoin [table " include " field1]
          append clipboard newline
      ]
      append clipboard "}"
      clipboard
]

Sample output1 (Wordpress DB):

[wp_comments|comment_ID;comment_post_ID;comment_author;comment_author_email;comment_author_url;comment_author_IP;comment_date;comment_date_gmt;comment_content;comment_karma;comment_approved;comment_agent;comment_type;comment_parent;user_id;]
[wp_links|link_id;link_url;link_name;link_image;link_target;link_description;link_visible;link_owner;link_rating;link_updated;link_rel;link_notes;link_rss;]
[wp_options|option_id;blog_id;option_name;option_value;autoload;]
[wp_postmeta|meta_id;post_id;meta_key;meta_value;]
[wp_posts|ID;post_author;post_date;post_date_gmt;post_content;post_title;post_excerpt;post_status;comment_status;ping_status;post_password;post_name;to_ping;pinged;post_modified;post_modified_gmt;post_content_filtered;post_parent;guid;menu_order;post_type;post_mime_type;comment_count;]
[wp_term_relationships|object_id;term_taxonomy_id;term_order;]
[wp_term_taxonomy|term_taxonomy_id;term_id;taxonomy;description;parent;count;]
[wp_terms|term_id;name;slug;term_group;]
[wp_usermeta|umeta_id;user_id;meta_key;meta_value;]
[wp_users|ID;user_login;user_pass;user_nicename;user_email;user_url;user_registered;user_activation_key;user_status;display_name;]

Sample Output2 (Sharetronix):

[posts|id;api_id;user_id;group_id;message;mentioned;attached;posttags;comments;date;date_lastedit;date_lastcomment;ip_addr;]
[posts_attachments|id;post_id;type;data;]
[posts_comments|id;api_id;post_id;user_id;message;mentioned;posttags;date;ip_addr;]
Bookmark and Share

Comments

[...] is sharetronix UML Class Diagrams created with this script (to be continued [...]

posted by Askuml.com: UML for mere mortals on 06.20.10 at 1:07 pm

Leave a comment