Convention for Database Tables: Difference between revisions

From Chorke Wiki
Jump to navigation Jump to search
Line 317: Line 317:
| <code>100,000</code> || <code>zzz,zzz</code> || <code>60,466,176</code>  || <code>2,176,782,335</code> || <code>2,116,316,160</code> || <code>user</code>, <code>admin</code>, <code>manager</code>
| <code>100,000</code> || <code>zzz,zzz</code> || <code>60,466,176</code>  || <code>2,176,782,335</code> || <code>2,116,316,160</code> || <code>user</code>, <code>admin</code>, <code>manager</code>
|-
|-
| <code>1,000,000</code> || <code>z,zzz,zzz</code> || <code>2,176,782,336</code>  || <code>78,364,164,095</code> || <code>76,187,381,760</code> || <code>staff</code>, <code>user</code>, <code>employee</code>
| <code>1,000,000</code> || <code>z,zzz,zzz</code> || <code>2,176,782,336</code>  || <code>78,364,164,095</code> || <code>76,187,381,760</code> || <code>oauth</code>, <code>client</code>, <code>invoice</code>
|-
|-
| <code>10,000,000</code> || <code>zz,zzz,zzz</code> || <code>78,364,164,096</code>  || <code>2,821,109,907,455</code> || <code>2,742,745,743,360</code> ||  
| <code>10,000,000</code> || <code>zz,zzz,zzz</code> || <code>78,364,164,096</code>  || <code>2,821,109,907,455</code> || <code>2,742,745,743,360</code> || <code>user</code>, <code>civic</code>, <code>staff</code>, <code>visa</code>, <code>passport</code>
|-
|-
| <code>100,000,000</code> || <code>zzz,zzz,zzz</code> || <code>2,821,109,907,456</code>  || <code>101,559,956,668,415</code> || <code>98,738,846,760,960</code> ||  
| <code>100,000,000</code> || <code>zzz,zzz,zzz</code> || <code>2,821,109,907,456</code>  || <code>101,559,956,668,415</code> || <code>98,738,846,760,960</code> || <code>cheque</code>, <code>invoice</code>, <code>certificate</code>
|-
|-
| <code>1,000,000,000</code> || <code>z,zzz,zzz,zzz</code> || <code>101,559,956,668,416</code>  || <code>3,656,158,440,062,975</code> || <code>3,554,598,483,394,560</code> ||
| <code>1,000,000,000</code> || <code>z,zzz,zzz,zzz</code> || <code>101,559,956,668,416</code>  || <code>3,656,158,440,062,975</code> || <code>3,554,598,483,394,560</code> ||  
|}
|}



Revision as of 08:06, 3 February 2020

static char *base36enc(long unsigned int value) {
	char base36[36] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	/* log(2**64) / log(36) = 12.38 => max 13 char + '\0' */
	char buffer[14];
	unsigned int offset = sizeof(buffer);

	buffer[--offset] = '\0';
	do {
		buffer[--offset] = base36[value % 36];
	} while (value /= 36);

	return strdup(&buffer[offset]); // warning: this must be free-d by the user
}

static long unsigned int base36dec(const char *text) {
	return strtoul(text, NULL, 36);
}

Types of Table

Order Code Types Purpose Tables Views
F A Audit Audit Tables M00TA00X00 ~ MZZTAZZX00 M00VA00X00 ~ MZZVAZZXZZ
D E Entries Entries Tables M00TE00X00 ~ MZZTEZZX00 M00VE00X00 ~ MZZVEZZXZZ
A I Identity Identity Tables M00TI00X00 ~ MZZTIZZX00 M00VI00X00 ~ MZZVIZZXZZ
E J Join Join Tables n - n M00TJ00X00 ~ MZZTJZZX00 M00VJ00X00 ~ MZZVJZZXZZ
G L Local Local Tables M00TL00X00 ~ MZZTLZZX00 M00VL00X00 ~ MZZVLZZXZZ
B M Metadata Metadata Tables M00TM00X00 ~ MZZTMZZX00 M00VM00X00 ~ MZZVMZZXZZ
C S Settings Settings Tables M00TS00X00 ~ MZZTSZZX00 M00VS00X00 ~ MZZVSZZXZZ
H V Versions Versions Tables M00TV00X00 ~ MZZTVZZX00 M00VV00X00 ~ MZZVVZZXZZ

Nomenclature

[M]{1}────────────────M ─┐
                         │
[0-9A-Z]{2}───────────00─┼─M00T─┐
                         │      │
[T|V]{1}──────────────T ─┘      │
                                │
[A|E|I|J|L|M|S|V]{1}──M ─┐      │
                         ├─M00 ─┼─M00TM00X00
[0-9A-Z]{2}───────────00─┘      │
                                │
[X]{1}────────────────X ─┐      │
                         ├─X00 ─┘
[0-9A-Z]{2}───────────00─┘

Audit Tables

[M]{1}───────M ─┐
                │
[0-9A-Z]{2}──00─┼─M00T─┐
                │      │
[T|V]{1}─────T ─┘      │
                       │
[A]{1}───────A ─┐      │
                ├─A00 ─┼─M00TA00X00
[0-9A-Z]{2}──00─┘      │
                       │
[X]{1}───────X ─┐      │
                ├─X00 ─┘
[0]{2}───────00─┘

Entries Tables

[M]{1}───────M ─┐
                │
[0-9A-Z]{2}──00─┼─M00T─┐
                │      │
[T|V]{1}─────T ─┘      │
                       │
[E]{1}───────E ─┐      │
                ├─E00 ─┼─M00TE00X00
[0-9A-Z]{2}──00─┘      │
                       │
[X]{1}───────X ─┐      │
                ├─X00 ─┘
[0]{2}───────00─┘

Identity Tables

[M]{1}───────M ─┐
                │
[0-9A-Z]{2}──00─┼─M00T─┐
                │      │
[T|V]{1}─────T ─┘      │
                       │
[I]{1}───────I ─┐      │
                ├─I00 ─┼─M00TI00X00
[0-9A-Z]{2}──00─┘      │
                       │
[X]{1}───────X ─┐      │
                ├─X00 ─┘
[0]{2}───────00─┘

Join Tables

[M]{1}───────M ─┐
                │
[0-9A-Z]{2}──00─┼─M00T─┐
                │      │
[T|V]{1}─────T ─┘      │
                       │
[J]{1}───────J ─┐      │
                ├─J00 ─┼─M00TJ00X00
[0-9A-Z]{2}──00─┘      │
                       │
[X]{1}───────X ─┐      │
                ├─X00 ─┘
[0]{2}───────00─┘

Local Tables

[M]{1}───────M ─┐
                │
[0-9A-Z]{2}──00─┼─M00T─┐
                │      │
[T|V]{1}─────T ─┘      │
                       │
[L]{1}───────L ─┐      │
                ├─L00 ─┼─M00TL00X00
[0-9A-Z]{2}──00─┘      │
                       │
[X]{1}───────X ─┐      │
                ├─X00 ─┘
[0]{2}───────00─┘

Metadata Tables

[M]{1}───────M ─┐
                │
[0-9A-Z]{2}──00─┼─M00T─┐
                │      │
[T|V]{1}─────T ─┘      │
                       │
[M]{1}───────M ─┐      │
                ├─M00 ─┼─M00TM00X00
[0-9A-Z]{2}──00─┘      │
                       │
[X]{1}───────X ─┐      │
                ├─X00 ─┘
[0]{2}───────00─┘

Settings Tables

[M]{1}───────M ─┐
                │
[0-9A-Z]{2}──00─┼─M00T─┐
                │      │
[T|V]{1}─────T ─┘      │
                       │
[S]{1}───────S ─┐      │
                ├─S00 ─┼─M00TS00X00
[0-9A-Z]{2}──00─┘      │
                       │
[X]{1}───────X ─┐      │
                ├─X00 ─┘
[0]{2}───────00─┘

Versions Tables

[M]{1}───────M ─┐
                │
[0-9A-Z]{2}──00─┼─M00T─┐
                │      │
[T|V]{1}─────T ─┘      │
                       │
[V]{1}───────V ─┐      │
                ├─V00 ─┼─M00TV00X00
[0-9A-Z]{2}──00─┘      │
                       │
[X]{1}───────X ─┐      │
                ├─X00 ─┘
[0]{2}───────00─┘

Data Size Convention

;data size convention (where n is integer number)
STRING  : 1 + 2 + 4 + 08 + 16 + 32 + 64 + 128 + 256 + 2^n
NUMBER  : 3 + 6 + 9 + 12 + 15 + 18 + 21 + 024
DATE    : yyyy-MM-dd | yyyy-MM-dd'T'HH:mm:ss
BOOLEAN : 0 + 1



Id Field Convention

JavaScript

var Chorke=Chorke||(function(me){
    me = {
        $class   : 'Chorke',
        $package : 'Default',
    };
    return me;
})();
/**
 * @public
 * @static
 */
;Chorke.Base36||(function($, me, RADIX){
    RADIX = 36;
    me    = {
        $package: 'Chorke',
        $class  : 'Chorke.Base36',
        Encode  : function(number, base36){
            base36  = (number).toString(RADIX)
            base36  = base36.toUpperCase()
            return base36
        },
        Decode  : function(base36, number){
            number  = parseInt(base36, RADIX)
            return number
        }
    };
    $.Base36 = me;
})(Chorke);
/**
 * @public
 * @static
 */
;Chorke.Severity||(function($, w, me){
    me = {
        $package: 'Chorke',
        $class  : 'Chorke.Severity',
        Info    : function(message){
            w.console&&w.console.info(message)
        }
    };
    $.Severity = me;
})(Chorke, window);

/**
 * @anonymous
 * @static
 */
(function($){
    $.Severity.Info($.Base36.Encode(123456789));
    $.Severity.Info($.Base36.Decode("2R4Y"));
})(Chorke);


// Output
// 21I3V9
// 128482

Java

public class Base36 {
    public static final int RADIX = 36;

    public static String encode(int integer) {
        String base36 = Integer.toString(integer, RADIX);
        return base36.toUpperCase();
    }

    public static int decode(String base36) {
        String lower = base36.toLowerCase();
        return Integer.parseInt(lower, RADIX);
    }
}

Size Index

Base36 Start Base36 End Decimal Start Decimal End No.of Elements Usages as ID
0 z 0 35 36 type, site, status, group, category
10 zz 36 1,295 1,260 type, user, module, table, project
100 zzz 1,296 46,655 45,360 type, group, category, subcategory
1,000 z,zzz 46,656 1,679,615 1,632,960 user, category, subcategory
10,000 zz,zzz 1,679,616 60,466,175 58,786,560 category, subcategory, branch
100,000 zzz,zzz 60,466,176 2,176,782,335 2,116,316,160 user, admin, manager
1,000,000 z,zzz,zzz 2,176,782,336 78,364,164,095 76,187,381,760 oauth, client, invoice
10,000,000 zz,zzz,zzz 78,364,164,096 2,821,109,907,455 2,742,745,743,360 user, civic, staff, visa, passport
100,000,000 zzz,zzz,zzz 2,821,109,907,456 101,559,956,668,415 98,738,846,760,960 cheque, invoice, certificate
1,000,000,000 z,zzz,zzz,zzz 101,559,956,668,416 3,656,158,440,062,975 3,554,598,483,394,560

References