ivan tsai
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # database ### MySQL/MariaDB 系統支援MySQL/MariaDB,基於OO導向的非關聯式資料庫管理系統(dbal) 並採用ORM系統(object relational mapping) 一、ORM系統 --- Object-Relational Mapping (ORM, O/RM, or O/R mapping)一詞就是將關聯式資料庫映射至物件導向的資料抽象化技術。 其理念是將資料庫的內容映射為物件,讓程式開發人員可以用操作物件的方式對資料庫進行操作,而不直接使用SQL語法對資料庫進行操作。 讓程式設計師不用管底層的資料庫系統是哪種廠牌或哪個版本的資料庫(如:SQL Server、Oracle、DB2、MySQL、Sybase、DBMaker…),僅須用同一套語法撰寫存取資料庫的邏輯。 當底層資料庫的實作品變更時,由於程式設計師並不直接對資料庫進行操作,因此程式內容幾乎不用修改,也就是降低了物件導向程式與資料庫之間的耦合關係 二、為什麽要使用ORM --- ## 2.1. 操作SQL語法的重複性 在ORM之前我們知道通過ADO.NET可以訪問資料庫。或者更進一步,學過三層架構的開發人員,知道可以將通過ADO.NET對資料庫的操作提取到一個單獨的類SqlHelper中,然後在DAL層調用SqlHelper類的方法實現對資料庫的操作。 即使你這樣做了,在數據訪問層(DAL)層,還是要寫大量的code,而且我們都知道對資料庫的訪問無非增、刪、改、查四種操作,那麼我們很容易想到我們做了大量的重複性工作。只是因為操作的表不同,我們可能需要花費大量的時間編寫針對該表的增刪改查語句,那麼有沒有一種方式能自動生成這些語句呢?這樣的話,我們就可以吧主要的精力或者更多的時間投入到特殊業務的處理上。 ## 2.2 大量SQL語句影響程序的擴展性和靈活性 我們知道之前我們編寫的程序和資料庫之間的耦合性很緊密,如果我們操作的是SQL Server資料庫,我們就需要引入對應的類庫(SqlConnection等),這樣如果需要更換資料庫,那麼,數據訪問層的代碼就需要重新書寫。 在資料庫中表現為關係數據,而在內存中表現為對象。應用程序處理對像很容易,但是很難處理關係數據。 ORM做到了關係數據和對像數據之間的映射,ORM可以通過映射關係自動產生SQL語句,ORM在業務邏輯層和數據層之間充當橋樑。 ## 2.3 ORM核心原則: - 簡單性 - 以最基本的形式建模數據 - 傳達性 - 資料庫結構被任何人都能理解的語言文化 - 精確性 - 基於數據模型創建正確標準化的結構 三、ORM的優缺點 --- ## 3.1 優點 1. 隱藏了數據訪問細節,“封閉”的通用資料庫交互,ORM的核心。他使​​得我們的通用數據交互變得簡單易行,並且完全不用考慮該死的SQL語句。快速開發,由此而來。 2. ORM使用我們構造固化數據結構變得簡單易行。 3. ORM可以防止SQL的注入攻擊(SQL-Injection) 4. 面向對象不用編碼,就可以向操作對像一樣操作資料庫 5. 提高開發效率,ORM可以自動對實體對象與資料庫中表進行字段與屬性的映射,不需要單獨的數據訪問層就可以數據進行增刪改查。 6. 方便轉移資料庫,當資料庫發生改變時,不需要對模型進行改動,只需要修改映射關係就可以了。 在ORM年表的史前時代,我們需要將我們的對像模型轉化為一條條的SQL語句,通過直連或是DB helper在關係資料庫構造我們的資料庫體系。 而現在,基本上所有的ORM框架都提供了通過對像模型關係資料庫結構的功能 ## 3.2 缺點 1. 無可避免的,自動化意味著映射和關聯管理,代價是犧牲性能(早期,這是所有不喜歡ORM人的共同點)。現在的各種ORM框架都在嘗試使用各種方法來減輕這塊,效果還是很顯著的。 2. 面向對象的查詢語言作為一種資料庫與對象之間的過渡,雖然隱藏了數據層面的業務抽象,但並不能完全的屏蔽掉資料庫層的設計,並且無疑將半圓學習成本 3. 對於複雜查詢,ORM仍然力不從心!雖然可以實現,但是不值的(在Laravel上曾有過這樣的感觸,結果最後還是要寫raw sql)。視圖和存儲可以解決大部份問題 用SQL來作為輕量化 client 端,在 interface 與 data 端保有share nothing的原則,將程式所有的 status 保存在 database 中,優點為將program中的data同步完全交給 database 做處理,interface只從database中取得data並顯示再螢幕上(介面上),data處理交給後端的程式去執行。其中資料庫的ACID特性可以保證程式狀態的完整性,並實現程式狀態的儲存和復原。 >**Note** > > ACID,是指資料庫管理系統(DBMS)在寫入或更新資料的過程中,為保證事務(transaction)是正確可靠的,所必須具備的四個特性:原子性(atomicity,或稱不可分割性)、一致性(consistency)、隔離性(isolation,又稱獨立性)、持久性(durability)。

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully