Coding standards

Uit De Vliegende Brigade
Ga naar: navigatie, zoeken

Dit dus:

  • Gebruik in SQL '#' als commentaarteken
  • Hiërarchie: Gebruik bij voorkeur alleen headings en subheadings. Toch nog een extra niveau nodig? Subsubheadings: Zonder 'underline', en met ':'
  • Na een 'samenhangend geheel' twee regels overslaan. Ook als dit binnen commando's is
  • Etc.

Voorbeeld

#
# EanSku - Iteration 06 - Project delivery & project conclusion - Main script
################################################################################ ← 80 tekens voor headings. Dit is de max. breedte van regels
#
# * Project EanSku - March 2020-April 2020
# * This is the main script - Everything this project does, is incorporated in 
#   this single script
# * I should be able to start this script on an empty db bal_dwh_op_eansku_2020 
#   (except for sprocs) and have all deliverables generated (as long as 
#   deliverables are tables)
# * All 'long-term documentation' should be available here, or from here.
# * At the beginning of project EanSku, there were two distinct groups of 
#   products found, that could be deleted from the curren portfolio: 
#   "Ean-Specials" and "Ean-subspecials". These subprojects are not covered 
#   here. Probably, it would be a lot of work to find that project back and 
#   properly reconstruct it
#
#
# Subheading
######################################## ← 40 tekens voor subheadings
#
# Get a grip on the 51.000 SKUs for Specials that Example.com has on sale:
#
# * Reduce the number of products from 51.000 SKUs to a more manageable & 
#   realistic amount
# * Identify for which products people buy Specials
# * Identify for which products they don't buy Specials
# * Remove doubles: For some products, there are probably up to 5 SKUs 
#   (seriously!)
# * Remove doubles from Amz-sites
# * Apply Busco4-SKUs for all products
#
#
# Subsubheading 1:
#
# * Subsubheadings gebruik ik zo min mogelijk
# * Subsubheadings zonder 'underline', maar met ":"
#
#
# Subsubheading 2:
#
# En nog een subbusheading.
#
################################################################################
# Select database
################################################################################
#
use bal_dwh_op_eansku_2020;


################################################################################
# An annotated multiline query
################################################################################
#
# Here's some documentation about this amazing query, followed by one comment 
# line
#
# General stuff
########################################
#
select 
    wp_posts.id			as post_id,
    wp_posts.post_title		as post_title,
    wp_posts.post_name		as slug,
    wp_posts.post_content	as content,
    wp_posts.guid		as guid,
    wp_postmeta.meta_value	as sku,
    wp_postmeta_03.meta_value	as thumbnail_path,
    wp_postmeta_05.meta_value	as second_image_path,
    wp_postmeta_06.meta_value	as price
from 
    wp_posts


# First join to wp_postmeta to retrieve sku
########################################### ← I often make subheadings longer, to cover the heading
#
left join
    wp_postmeta
    on
    wp_posts.id = wp_postmeta.post_id


# Second join to wp_postmeta to retrieve "_thumbnail_id"
########################################################
#
# "_thumbnail_id" on its turn, is a wp_postmeta.product_id
#
left join
    wp_postmeta as wp_postmeta_02
    on
    wp_postmeta_02.post_id = wp_posts.id
    and
    wp_postmeta_02.meta_key = "_thumbnail_id"


# Where clause
########################################
#    
where 
    post_type="product"
    and
    post_status="publish"
    and
    wp_postmeta.meta_key="_sku"


# Limit
########################################
#
limit 
    0, 10;