Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First and foremost, <strong>make sure you have unicity constraints in place</strong> on the <code>ID</code> and <code>short_url_code</code> columns.</p> <p>When someone creates a new link:</p> <ol> <li>Get the next largest link <code>ID</code> from the database (<strong>for performance reasons you should really REALLY use <code>autoincrement</code> or <code>SEQUENCE</code></strong>, depending on what your RDBMS offers; otherwise go ahead and select <code>MAX(ID)+1</code> )</li> <li>Generate a short URL code (<code>http://website.com/[short url name]</code>) from <code>ID</code> using <code>base64_encode</code> or <em>any</em> other custom or standard encoding scheme</li> <li>Insert into the <code>links</code> table: <code>ID, short_url_code, destination_url</code></li> <li><p>If the insert fails because of a constraint violation go back to step 1 to try a new <code>ID</code>; you may have had a violation because:</p> <ol> <li>the same ID has already been used (i.e. inserted) in parallel by another thread/process etc. (this will <em>not</em> happen if you used <code>autoincrement</code> or <code>SEQUENCE</code>, and may happen quite often otherwise), and/or</li> <li>the same <code>short_url_code</code> has already been used as a custom URL (this will happen very seldomly unless someone is trying to cause trouble on your site)</li> </ol></li> <li><p>If the insert succeeded, commit and return the short URL to the user</p></li> </ol> <p>When someone creates a new link and passes a custom short URL:</p> <ol> <li>Perform the same step 1 as above</li> <li><strong>Instead of generating</strong> the short URL part from <code>ID</code> as in step 2 above, <strong>use the custom <code>short_url_code</code> provided by the user</strong></li> <li>Perform the same step 3 as above</li> <li>If the insert failed because of: <ol> <li>a constraint violation on <code>ID</code>: go back to step 1 to try a new <code>ID</code></li> <li>a constraint violation on <code>short_url_code</code>: return an error to the user asking him to pick a different custom URL, as the short URL he/she provided has already been used</li> </ol></li> <li>Perform the same step 5 as above</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload