Skip to content

feat: implement database/sql Scanner and driver.Valuer interfaces - #86

Open
AdamMagued wants to merge 1 commit into
sony:masterfrom
AdamMagued:feat-issue-80-sql-scanner-valuer
Open

AdamMagued wants to merge 1 commit into
sony:masterfrom
AdamMagued:feat-issue-80-sql-scanner-valuer

Conversation

@AdamMagued

Copy link
Copy Markdown

Resolves #80

Problem

Sonyflake generated IDs as bare uint64 primitives without implementing database/sql.Scanner or database/sql/driver.Valuer. Applications reading from SQL engines or ORMs could not scan Sonyflake IDs directly from database columns or bind them as driver parameters without manual conversions.

Changes

  1. Added type ID uint64 and alias type SonyflakeID = ID to provide first-class Sonyflake ID types.
  2. Implemented driver.Valuer on ID via Value() (driver.Value, error), returning int64(id) to match standard SQL BIGINT representations.
  3. Implemented sql.Scanner on *ID via Scan(src interface{}) error, supporting int64, uint64, int, integer subtypes, string, []byte (decimal string and 8-byte big-endian binary), and nil.
  4. Added helper methods String(), Int64(), Uint64(), ElapsedTime(), SequenceNumber(), MachineID(), Decompose(), and ParseID().
  5. Added Sonyflake.Next() (ID, error) to generate typed Sonyflake IDs directly.
  6. Added automated unit tests covering valid types, edge cases, invalid inputs, and interface compliance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support of Scanner and Valuer Interfaces in database/sql

1 participant