1 module hunt.sql.parser.SQLParserFeature; 2 3 import std.string; 4 5 struct SQLParserFeature { 6 enum SQLParserFeature KeepInsertValueClauseOriginalString = SQLParserFeature(0); 7 enum SQLParserFeature KeepSelectListOriginalString = SQLParserFeature(1); // for improved sql parameterized performance 8 enum SQLParserFeature UseInsertColumnsCache = SQLParserFeature(2); 9 enum SQLParserFeature EnableSQLBinaryOpExprGroup = SQLParserFeature(3); 10 enum SQLParserFeature OptimizedForParameterized = SQLParserFeature(4); 11 enum SQLParserFeature OptimizedForForParameterizedSkipValue = SQLParserFeature(5); 12 enum SQLParserFeature KeepComments = SQLParserFeature(6); 13 enum SQLParserFeature SkipComments = SQLParserFeature(7); 14 enum SQLParserFeature StrictForWall = SQLParserFeature(8); 15 16 enum SQLParserFeature PipesAsConcat = 9; // for mysql 17 18 this(int ord){ 19 mask = (1 << ord); 20 } 21 22 public int mask; 23 24 25 public static bool isEnabled(int features, SQLParserFeature feature) { 26 return (features & feature.mask) != 0; 27 } 28 29 public static int config(int features, SQLParserFeature feature, bool state) { 30 if (state) { 31 features |= feature.mask; 32 } else { 33 features &= ~feature.mask; 34 } 35 36 return features; 37 } 38 39 public static int of(SQLParserFeature[] features...) { 40 if (features is null) { 41 return 0; 42 } 43 44 int value = 0; 45 46 foreach(SQLParserFeature feature; features) { 47 value |= feature.mask; 48 } 49 50 return value; 51 } 52 53 bool opEquals(const SQLParserFeature h) nothrow { 54 return mask == h.mask ; 55 } 56 57 bool opEquals(ref const SQLParserFeature h) nothrow { 58 return mask == h.mask ; 59 } 60 } 61 62 unittest{ 63 SQLParserFeature p = SQLParserFeature.KeepComments; 64 assert(p == SQLParserFeature.KeepComments); 65 }