File tree Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Expand file tree Collapse file tree 1 file changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -35,15 +35,34 @@ SQLite's uuid extension provides the following:
35
35
- ` uuid_str(X)` - convert a UUID X into a well-formed UUID string
36
36
- ` uuid_blob(X)` - convert a UUID X into a 16-byte blob
37
37
38
- For example, in a rails app :
38
+ For more information about the extension itself, see the extension's [source code](https://sqlite.org/src/file/ext/misc/uuid.c?t=version-3.46.1).
39
+
40
+ # ## Examples
41
+
42
+ Use as a primary key in migrations :
43
+
44
+ ` ` `
45
+ bin/rails g model User email_address:uniq:index
46
+ ` ` `
47
+ ` ` ` ruby
48
+ class CreateUsers < ActiveRecord::Migration[8.0]
49
+ def change
50
+ create_table :users, id: :string, default: -> { "uuid()" }, limit: 36 do |t|
51
+ t.string :email_address, null: false
52
+ t.timestamps
53
+ end
54
+ add_index :users, :email_address, unique: true
55
+ end
56
+ end
57
+ ` ` `
58
+
59
+ Call SQL directly :
39
60
40
61
` ` ` ruby
41
62
ActiveRecord::Base.connection.execute("select uuid_str(uuid())")
42
63
#=> [{"uuid_str(uuid())"=>"56392d30-a2cf-47b9-895a-f8c1a1677bfc"}]
43
64
` ` `
44
65
45
- For more information about the extension itself, see the extension's [source code](https://sqlite.org/src/file/ext/misc/uuid.c?t=version-3.46.1).
46
-
47
66
# # How it works
48
67
49
68
This gem compiles SQLite's uuid extension into a shared library using Ruby's native-gem functionality.
You can’t perform that action at this time.
0 commit comments