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:
3535- ` uuid_str(X)` - convert a UUID X into a well-formed UUID string
3636- ` uuid_blob(X)` - convert a UUID X into a 16-byte blob
3737
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 :
3960
4061` ` ` ruby
4162ActiveRecord::Base.connection.execute("select uuid_str(uuid())")
4263#=> [{"uuid_str(uuid())"=>"56392d30-a2cf-47b9-895a-f8c1a1677bfc"}]
4364` ` `
4465
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-
4766# # How it works
4867
4968This 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