Skip to content

Commit

Permalink
LID v1
Browse files Browse the repository at this point in the history
  • Loading branch information
choval committed Aug 4, 2019
0 parents commit 48a34bd
Show file tree
Hide file tree
Showing 10 changed files with 2,079 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor/
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2019 Osvaldo Jiang

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
119 changes: 119 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# LID

LID (LongID) is a 64-bit number used to identify rows in a database.
Made specifically for use with BIGINT/LONGINT in databases. Includes a checksum to verify data.

## Install

```sh
composer require choval/lid
```

## Format

It is built using a base 62:

```
0123456789
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
```

* Except the web format, see <a href="#web">Web</a>.

The checksum is in the first character.

### Examples

```
NUM: 9223372036854775807
WEB: 45FE-KXVC-3KT2-6XC7
LID: 4aZl:8N0y:58M7
NUM: 8057322199735401981
WEB: 14V7-27T8-8CT6-54X1
LID: 19Bc:CvJ3:BrCR
NUM: 495653535173419733
WEB: 8061-03H6-471H-T96H
LID: 80AC:66ri:lnk9
NUM: 21398
WEB: 3000-0000-0000-2H9V
LID: 3000:0000:05z8
```


<a name="web"></a>
## Web

A different base is used for the web format.

Altough longer in length due to a shorter base, it is easier for dictation (across dialects) and more error friendly for OCR engines.

Alias characters are replaced.

```
0 - zero - alias: OoDQ
1 - one - alias: Iil
2 - two - alias: Zz
3 - three
4 - four - alias: AYy
5 - five - alias: Ss
6 - six - alias: Gbh
7 - seven - alias:
8 - eight - alias: BRg
9 - nine - alias: q
C - charlie
E - echo
F - foxtrot
H - hotel
J - juliett
K - kilo
N - november - alias: Mm
T - tango - alias: Pp
V - victor - alias: UuWw
X - xray
```

## Usage

```php
/**
* Basic usage
*/
$lid = new Lid( 21398 );
echo $lid->id();
// 3000:0000:05z8
echo $lid->web();
// 3000-0000-0000-2H9V
echo $lid->number();
// 21398

/**
* The constructor accepts an int, a LID or a Web LID
*/
$lid = new Lid( '3000-0000-0000-2H9V' );
echo $lid->id();
// 3000:0000:05z8
echo $lid->web();
// 3000-0000-0000-2H9V
echo $lid->number();
// 21398

/**
* Notice how we pass characters not in the base.
*/
$lid = new Lid( '3ooo-oOoo-ooo0-zHqU' );
echo $lid->id();
// 3000:0000:05z8
echo $lid->web();
// 3000-0000-0000-2H9V
echo $lid->number();
// 21398
```

## License

MIT, see LICENSE

22 changes: 22 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "choval/lid",
"description": "A long 64-bit number used to identify rows in a database",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Osvaldo Jiang",
"email": "[email protected]"
}
],
"autoload": {
"psr-4": {
"Choval\\": "src/"
}
},
"require": {
},
"require-dev": {
"phpunit/phpunit": "^7"
}
}
Loading

0 comments on commit 48a34bd

Please sign in to comment.