| | | 1 | | namespace Elsa.Persistence.VNext.Builders; |
| | | 2 | | |
| | 0 | 3 | | public class PersistenceTableBuilder(string name, string? schema) |
| | | 4 | | { |
| | 0 | 5 | | private readonly List<PersistenceColumn> _columns = []; |
| | 0 | 6 | | private readonly List<PersistenceIndex> _indexes = []; |
| | | 7 | | private PersistencePrimaryKey? _primaryKey; |
| | | 8 | | |
| | | 9 | | public PersistenceTableBuilder Column(string name, PersistenceColumnType type, bool nullable = true, int? length = n |
| | | 10 | | { |
| | 0 | 11 | | _columns.Add(new PersistenceColumn(name, type, nullable, length)); |
| | 0 | 12 | | return this; |
| | | 13 | | } |
| | | 14 | | |
| | | 15 | | public PersistenceTableBuilder RequiredColumn(string name, PersistenceColumnType type, int? length = null) |
| | | 16 | | { |
| | 0 | 17 | | return Column(name, type, false, length); |
| | | 18 | | } |
| | | 19 | | |
| | | 20 | | public PersistenceTableBuilder PrimaryKey(string name, params string[] columns) |
| | | 21 | | { |
| | 0 | 22 | | _primaryKey = new PersistencePrimaryKey(name, columns.ToList()); |
| | 0 | 23 | | return this; |
| | | 24 | | } |
| | | 25 | | |
| | | 26 | | public PersistenceTableBuilder Index(string name, string column, bool unique = false) |
| | | 27 | | { |
| | 0 | 28 | | return Index(name, [column], unique); |
| | | 29 | | } |
| | | 30 | | |
| | | 31 | | public PersistenceTableBuilder Index(string name, IReadOnlyList<string> columns, bool unique = false) |
| | | 32 | | { |
| | 0 | 33 | | _indexes.Add(new PersistenceIndex(name, columns.ToList(), unique)); |
| | 0 | 34 | | return this; |
| | | 35 | | } |
| | | 36 | | |
| | | 37 | | public PersistenceTable Build() |
| | | 38 | | { |
| | 0 | 39 | | return new PersistenceTable(Name: name, Schema: schema, Columns: _columns.ToList(), PrimaryKey: _primaryKey, Ind |
| | | 40 | | } |
| | | 41 | | } |