自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

軟件設(shè)計技巧之數(shù)據(jù)庫設(shè)計還能這樣玩

運維 數(shù)據(jù)庫運維
隨著軟件設(shè)計的發(fā)展,設(shè)計思想不斷革新,作為程序員,就需要不斷的學習,不斷的嘗試新方法,本文將介紹一種新的數(shù)據(jù)庫設(shè)計方法,個人感覺非常符合現(xiàn)代設(shè)計風格,接下來一起看看吧。

數(shù)據(jù)庫設(shè)計回顧

記得剛學習java開發(fā)的時候,老師推薦PowerDesigner設(shè)計數(shù)據(jù)庫,圖形化更加直觀易懂。

后來工作后,實際開發(fā),喜歡直接連接數(shù)據(jù)庫操作,因此使用Navicat作為數(shù)據(jù)庫管理工具,順帶包攬設(shè)計工作。

而在團隊協(xié)作中,數(shù)據(jù)庫文檔是評審必須的,想想自己整理的word文檔,免不了會吐槽一番。最近幾年,word文檔寫的很少了(除非正式的文檔),因為markdown的出現(xiàn),更加符合程序員的編寫習慣,感覺就和寫代碼一樣,縮進、特殊標記、代碼插入、表格等,很方便的就能實現(xiàn)。

為了講下面的內(nèi)容,這里我簡單說明下markdown是什么。

markdown是一種標記語言,使用更加易懂的純文本格式,很方便實現(xiàn)寫文章所需的各種效果。

那么,你有沒有想過,數(shù)據(jù)庫設(shè)計也能通過類似的標記語言呢?

數(shù)據(jù)庫標記語言

今天要講的主角正式登場(^_^),她就是DBML,全稱是Database Markup Language(數(shù)據(jù)庫標記語言)。講之前,先來張靚照瞧瞧

軟件設(shè)計技巧之數(shù)據(jù)庫設(shè)計還能這樣玩

從上圖可以看到,table、pk、varchar等關(guān)鍵字,再熟悉不過了。這種語言是專門為數(shù)據(jù)庫設(shè)計的,所以叫數(shù)據(jù)庫標記語言,接下來我們就想起的細品下她的美好。

DBML語法

  • 表定義
  1. Table table_name { 
  2.     column_name column_type [column_settings] 

table_name:表名

column_name:字段名

column_type:字段類型

column_settings:字段的設(shè)置

  • 字段定義
  1. Table buildings { 
  2.     ... 
  3.     address varchar(255) [uniquenot null, note: 'to include unit number'
  4.     id integer [ pk, uniquedefault: 123, note: 'Number' ] 

主鍵:primary key 或 pk

空/非空:null 或 not null

注釋:note

唯一索引:unique

默認值:default

  • 索引定義
  1. Table bookings { 
  2.   id integer 
  3.   country varchar 
  4.   booking_date date 
  5.   created_at timestamp 
  6.  
  7.   indexes { 
  8.       (id, country) [pk] // composite primary key 
  9.       created_at [note: 'Date'
  10.       booking_date 
  11.       (country, booking_date) [unique
  12.       booking_date [type: hash] 
  13.       (`id*2`) 
  14.       (`id*3`,`getdate()`) 
  15.       (`id*3`,id) 
  16.   } 

主要分三種索引:

單字段索引、復合索引、表達式索引

  • 外鍵關(guān)系定義
  1. //Long form 
  2. Ref name_optional { 
  3.   table1.column1 < table2.column2 
  4.  
  5. //Short form: 
  6. Ref name_optional: table1.column1 < table2.column2 
  7.  
  8. // Inline form 
  9. Table posts { 
  10.     id integer 
  11.     user_id integer [ref: > users.id] 

 

  • 注釋
  1. // Inline form 

使用雙斜杠即可

  • 備注
  1. Table users { 
  2.   id int [pk] 
  3.   name varchar 
  4.  
  5.   Note: 'This is a note of this table' 
  6.   // or 
  7.   Note { 
  8.     'This is a note of this table' 
  9.   } 
  • 枚舉
  1. enum job_status { 
  2.     created [note: 'Waiting to be processed'
  3.     running 
  4.     done 
  5.     failure 

DBML工具

通過DBML可以讓表設(shè)計,通過純文本的方式,很方便的描述。那么,如果僅僅是這樣的,肯定不夠吸引,我猜你還希望

  • DBML轉(zhuǎn)成SQL語句
  • SQL語句轉(zhuǎn)換成DBML
  • 可視化

當然了,這些DBML都給你提供了,先來看張圖

軟件設(shè)計技巧之數(shù)據(jù)庫設(shè)計還能這樣玩

這個是所見即所得,在線工具。

至于DBML與SQL的互相轉(zhuǎn)化,DBML提供了基于node的命令工具dbml2sql、sql2dbml

總結(jié)

DBML是一個新型的數(shù)據(jù)庫設(shè)計工具,當然有人喜歡,有人吐槽,當然希望你能夠喜歡哈。軟件設(shè)計隨著時光的推進,很多新的理念被推出,作為程序員,當然是要不斷的吸收和轉(zhuǎn)化。

責任編輯:龐桂玉 來源: 今日頭條
相關(guān)推薦

2011-03-10 11:17:03

數(shù)據(jù)庫設(shè)計技巧

2020-11-16 13:38:31

PostMessage

2021-07-28 06:10:47

拖拽設(shè)計器 transmat

2021-09-05 07:55:37

前端Emoji 表情

2021-04-01 05:40:53

分庫分表數(shù)據(jù)庫MySQL

2024-08-02 08:38:20

Controller接口地址

2013-05-08 09:12:44

2011-07-21 14:33:02

設(shè)計模式

2020-12-30 09:45:50

MySQL數(shù)據(jù)分離數(shù)據(jù)庫

2017-08-28 15:00:20

軟件系統(tǒng)架構(gòu)風格

2019-08-12 14:45:50

軟件設(shè)計Java

2021-01-30 07:51:59

微信微信8.0騰訊

2011-05-19 15:25:20

數(shù)據(jù)庫結(jié)構(gòu)

2011-03-01 16:00:08

java數(shù)據(jù)庫

2019-10-29 16:02:14

開發(fā)者技能工具

2016-11-29 08:50:17

數(shù)據(jù)庫軟件架構(gòu)

2011-04-15 13:28:44

數(shù)據(jù)庫設(shè)計

2011-03-10 11:12:59

數(shù)據(jù)庫

2019-07-30 05:15:29

數(shù)據(jù)庫軟件架構(gòu)數(shù)據(jù)

2024-12-03 09:45:34

點贊
收藏

51CTO技術(shù)棧公眾號