| | | 1 | | namespace Elsa.Persistence.VNext.Builders; |
| | | 2 | | |
| | 42 | 3 | | public class PersistenceStorageUnitBuilder(string name, string? @namespace) |
| | | 4 | | { |
| | 42 | 5 | | private readonly List<PersistenceField> _fields = []; |
| | 42 | 6 | | private readonly List<PersistenceIndex> _indexes = []; |
| | | 7 | | private PersistencePrimaryKey? _key; |
| | | 8 | | |
| | | 9 | | public PersistenceStorageUnitBuilder Field(string name, PersistenceColumnType type, bool nullable = true, int? lengt |
| | | 10 | | { |
| | 279 | 11 | | _fields.Add(new PersistenceField(name, type, nullable, length)); |
| | 279 | 12 | | return this; |
| | | 13 | | } |
| | | 14 | | |
| | | 15 | | public PersistenceStorageUnitBuilder RequiredField(string name, PersistenceColumnType type, int? length = null) |
| | | 16 | | { |
| | 224 | 17 | | return Field(name, type, false, length); |
| | | 18 | | } |
| | | 19 | | |
| | | 20 | | public PersistenceStorageUnitBuilder Key(string name, params string[] fields) |
| | | 21 | | { |
| | 42 | 22 | | _key = new PersistencePrimaryKey(name, fields.ToList()); |
| | 42 | 23 | | return this; |
| | | 24 | | } |
| | | 25 | | |
| | | 26 | | public PersistenceStorageUnitBuilder Index(string name, string field, bool unique = false) |
| | | 27 | | { |
| | 82 | 28 | | return Index(name, [field], unique); |
| | | 29 | | } |
| | | 30 | | |
| | | 31 | | public PersistenceStorageUnitBuilder Index(string name, IReadOnlyList<string> fields, bool unique = false) |
| | | 32 | | { |
| | 119 | 33 | | _indexes.Add(new PersistenceIndex(name, fields.ToList(), unique)); |
| | 119 | 34 | | return this; |
| | | 35 | | } |
| | | 36 | | |
| | | 37 | | public PersistenceStorageUnit Build() |
| | | 38 | | { |
| | 42 | 39 | | return new PersistenceStorageUnit(Name: name, Namespace: @namespace, Fields: _fields.ToList(), Key: _key, Indexe |
| | | 40 | | } |
| | | 41 | | } |