Skip to content

Commit af41216

Browse files
committed
update readme
1 parent 220b5eb commit af41216

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

README.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff 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
4162
ActiveRecord::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

4968
This gem compiles SQLite's uuid extension into a shared library using Ruby's native-gem functionality.

0 commit comments

Comments
 (0)