Files
bible/rules/patterns/identifier-normalization/README.md
Michael Chus a44133aff2 Move inline code examples out of normative contracts
identifier-normalization, no-hardcoded-vendors,
vendor-installer-verification, and build-version-display follow the
go-database split: rules in contract.md, snippets in README.md. Routed
contract reads get cheaper; examples stay available on demand. Lint now
also rejects stale kit/patterns references.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-12 10:00:02 +03:00

1.2 KiB

Identifier Normalization Pattern Notes

This file keeps examples. The normative rules live in contract.md.

Go — сравнение

import "strings"

func SameIdentifier(a, b string) bool {
    return strings.EqualFold(a, b)
}

Go — дедупликация

func deduplicateBySerial(items []Device) []Device {
    seen := make(map[string]struct{})
    result := items[:0]
    for _, item := range items {
        key := strings.ToLower(item.SerialNumber)
        if _, exists := seen[key]; !exists {
            seen[key] = struct{}{}
            result = append(result, item)
        }
    }
    return result
}

SQL — поиск и уникальность

Поиск:

SELECT * FROM devices WHERE LOWER(serial_number) = LOWER(?);

Уникальный индекс (MySQL / MariaDB):

-- Collation ci обеспечивает case-insensitive уникальность
ALTER TABLE devices MODIFY serial_number VARCHAR(255)
    CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

ALTER TABLE devices ADD UNIQUE INDEX uniq_serial (serial_number);

SQLite:

CREATE UNIQUE INDEX uniq_serial ON devices (LOWER(serial_number));