Answers.Body: <p>The BAO is not required, but it is what we always used to do. So the standard approach is: the API uses the BAO/DAO functions to insert and select. You can find a pretty simple example here: <a href="https://github.com/CiviCooP/no.maf.oppgavexml/tree/master/CRM/Oppgavexml" rel="nofollow">https://github.com/CiviCooP/no.maf.oppgavexml/tree/master/CRM/Oppgavexml</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-10T07:04:25.783Z
Answers.LastActivityDate: 2015-08-10T07:04:25.783Z
Answers.UserDisplayName: ErikH - CiviCooP
Body: <p>I am looking for a best practice approach. I am working on a module extension, which involves creation, retrieval and deletion of an entity(object). </p>
  
  <p>I have created the DAO files for them, I am looking to the write place to write insertion and selection queries. Currently I am confused about writing them in a BAO file or the API functions. </p>
  
  <p>Is writing this code directly in API functions a bad approach, and having a BAO is a necessity. Also, if we create a BAO is there a guide I should follow about what to do and what not to do. </p>
  
Tags: <database>
Title: Database Insertion and Deletion
ThreadText: # Database Insertion and Deletion
  
  (Asked by: username_0 on 2015-08-09)
  
  I am looking for a best practice approach. I am working on a module extension, which involves creation, retrieval and deletion of an entity(object).
  
  I have created the DAO files for them, I am looking to the write place to write insertion and selection queries. Currently I am confused about writing them in a BAO file or the API functions.
  
  Is writing this code directly in API functions a bad approach, and having a BAO is a necessity. Also, if we create a BAO is there a guide I should follow about what to do and what not to do.
  
  **Tags:** database
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-08-10. Score: 1
  
  The BAO is not required, but it is what we always used to do. So the standard approach is: the API uses the BAO/DAO functions to insert and select. You can find a pretty simple example here: <https://github.com/CiviCooP/no.maf.oppgavexml/tree/master/CRM/Oppgavexml>
  
  
  ---
  
  