Skip to content

Commit

Permalink
Showcase ulid+data use
Browse files Browse the repository at this point in the history
  • Loading branch information
kzu committed Dec 21, 2024
1 parent 40cee34 commit 58ea63f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,19 @@ public readonly partial record struct ProductId : IStructId<Ulid>;
public record Product(ProductId Id, string Name);

// Create a new product with a new Ulid-based id
var product = new Product(ProductId.New(), "Product Name");
var productId = Ulid.NewUlid();
var product = new Product(new ProductId(productId), "Product");

// Seed data
connection.Execute("INSERT INTO Products (Id, Name) VALUES (@Id, @Name)", new Product(ProductId.New(), "Product1"));
connection.Execute("INSERT INTO Products (Id, Name) VALUES (@Id, @Name)", product);
connection.Execute("INSERT INTO Products (Id, Name) VALUES (@Id, @Name)", new Product(ProductId.New(), "Product2"));

// showcase we can query by the underlying ulid
var saved1 = connection.QueryFirst<Product>("SELECT * FROM Products WHERE Id = @Id", new { Id = productId });

// showcase we can query by the ulid-based struct id
var saved2 = connection.QueryFirst<Product>("SELECT * FROM Products WHERE Id = @Id", new { Id = new ProductId(productId) });
```

## Customization via Templates
Expand Down

0 comments on commit 58ea63f

Please sign in to comment.