snowflaked 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +7 -1
- data/ext/snowflaked/Cargo.toml +1 -1
- data/lib/snowflaked/model_extensions.rb +8 -2
- data/lib/snowflaked/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4a6f86e1432fc8b11f282674da8568ffecb835bb5aba3d5c52c124acb4a55ace
|
|
4
|
+
data.tar.gz: 2d13a338cceed05710c0afa3e56896d8199d90b1934ac259e256bed49ba8c3cf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 54d45cfb0b0f503e8cc839ac7530439582e08ee11a98e3ec8a79bd9cc3bb0539cd8a0096e2d6618a9015c712bc02e8423ee18dc3d325eb695bdb4e413ad998dd
|
|
7
|
+
data.tar.gz: 4f291445d0e558e1e856f146d5972d52ac068ee907cb20aa4a2ea8d9eb0be818c3d4b53738e0b3ade960662aa8a5f05e6e616f210e0c7a3de7c37d089cbe9454
|
data/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
[](https://rubygems.org/gems/snowflaked)
|
|
6
6
|
[](LICENSE.txt)
|
|
7
7
|
|
|
8
|
-
A high-performance, thread-safe Snowflake ID generator for Ruby, powered by Rust.
|
|
8
|
+
A database-agnostic, high-performance, thread-safe Snowflake ID generator for Ruby, powered by Rust.
|
|
9
9
|
|
|
10
10
|
Snowflake IDs are 64-bit unique identifiers that encode a timestamp, machine ID, and sequence number. They're time-sortable (IDs created later are always larger), making them ideal for distributed systems where you need unique IDs without coordination between machines. Unlike UUIDs, Snowflake IDs are smaller, sortable, and index-friendly for databases.
|
|
11
11
|
|
|
@@ -143,6 +143,12 @@ Snowflaked.machine_id(id)
|
|
|
143
143
|
# => 42
|
|
144
144
|
```
|
|
145
145
|
|
|
146
|
+
## Benchmarks
|
|
147
|
+
|
|
148
|
+
See [BENCHMARKS.md](benchmarks/BENCHMARKS.md) for more details.
|
|
149
|
+
|
|
150
|
+
tl;dr: Snowflake IDs have a negligible performance impact compared to database-backed IDs.
|
|
151
|
+
|
|
146
152
|
## Requirements
|
|
147
153
|
|
|
148
154
|
- Ruby >= 3.2
|
data/ext/snowflaked/Cargo.toml
CHANGED
|
@@ -6,7 +6,7 @@ module Snowflaked
|
|
|
6
6
|
|
|
7
7
|
included do
|
|
8
8
|
class_attribute :_snowflake_attributes, instance_writer: false, default: [:id]
|
|
9
|
-
|
|
9
|
+
after_initialize :_generate_snowflake_ids, if: :new_record?
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
class_methods do
|
|
@@ -14,6 +14,7 @@ module Snowflaked
|
|
|
14
14
|
attrs = attributes.map(&:to_sym)
|
|
15
15
|
attrs |= [:id] if id
|
|
16
16
|
self._snowflake_attributes = attrs
|
|
17
|
+
@_snowflake_attributes_with_columns = nil
|
|
17
18
|
end
|
|
18
19
|
|
|
19
20
|
def _snowflake_columns_from_comments
|
|
@@ -25,12 +26,17 @@ module Snowflaked
|
|
|
25
26
|
[]
|
|
26
27
|
end
|
|
27
28
|
end
|
|
29
|
+
|
|
30
|
+
def _snowflake_attributes_with_columns
|
|
31
|
+
@_snowflake_attributes_with_columns ||= (_snowflake_attributes | _snowflake_columns_from_comments)
|
|
32
|
+
end
|
|
28
33
|
end
|
|
29
34
|
|
|
30
35
|
private
|
|
31
36
|
|
|
32
37
|
def _generate_snowflake_ids
|
|
33
|
-
attributes_to_generate = self.class.
|
|
38
|
+
attributes_to_generate = self.class._snowflake_attributes_with_columns
|
|
39
|
+
return if attributes_to_generate.empty?
|
|
34
40
|
|
|
35
41
|
attributes_to_generate.each do |attribute|
|
|
36
42
|
next if self[attribute].present?
|
data/lib/snowflaked/version.rb
CHANGED