Version 4 #6

Merged
danieljsummers merged 30 commits from version-four into main 2024-08-19 23:30:39 +00:00
2 changed files with 51 additions and 9 deletions
Showing only changes of commit 433302d995 - Show all commits

View File

@ -45,43 +45,57 @@ type Field = {
/// The value of the field /// The value of the field
Value: obj Value: obj
/// The name of the parameter for this field
ParameterName: string option
/// The table qualifier for this field
Qualifier: string option
} with } with
/// Create an equals (=) field criterion /// Create an equals (=) field criterion
static member EQ name (value: obj) = static member EQ name (value: obj) =
{ Name = name; Op = EQ; Value = value } { Name = name; Op = EQ; Value = value; ParameterName = None; Qualifier = None }
/// Create a greater than (>) field criterion /// Create a greater than (>) field criterion
static member GT name (value: obj) = static member GT name (value: obj) =
{ Name = name; Op = GT; Value = value } { Name = name; Op = GT; Value = value; ParameterName = None; Qualifier = None }
/// Create a greater than or equal to (>=) field criterion /// Create a greater than or equal to (>=) field criterion
static member GE name (value: obj) = static member GE name (value: obj) =
{ Name = name; Op = GE; Value = value } { Name = name; Op = GE; Value = value; ParameterName = None; Qualifier = None }
/// Create a less than (<) field criterion /// Create a less than (<) field criterion
static member LT name (value: obj) = static member LT name (value: obj) =
{ Name = name; Op = LT; Value = value } { Name = name; Op = LT; Value = value; ParameterName = None; Qualifier = None }
/// Create a less than or equal to (<=) field criterion /// Create a less than or equal to (<=) field criterion
static member LE name (value: obj) = static member LE name (value: obj) =
{ Name = name; Op = LE; Value = value } { Name = name; Op = LE; Value = value; ParameterName = None; Qualifier = None }
/// Create a not equals (<>) field criterion /// Create a not equals (<>) field criterion
static member NE name (value: obj) = static member NE name (value: obj) =
{ Name = name; Op = NE; Value = value } { Name = name; Op = NE; Value = value; ParameterName = None; Qualifier = None }
/// Create a BETWEEN field criterion /// Create a BETWEEN field criterion
static member BT name (min: obj) (max: obj) = static member BT name (min: obj) (max: obj) =
{ Name = name; Op = BT; Value = [ min; max ] } { Name = name; Op = BT; Value = [ min; max ]; ParameterName = None; Qualifier = None }
/// Create an exists (IS NOT NULL) field criterion /// Create an exists (IS NOT NULL) field criterion
static member EX name = static member EX name =
{ Name = name; Op = EX; Value = obj () } { Name = name; Op = EX; Value = obj (); ParameterName = None; Qualifier = None }
/// Create a not exists (IS NULL) field criterion /// Create a not exists (IS NULL) field criterion
static member NEX name = static member NEX name =
{ Name = name; Op = NEX; Value = obj () } { Name = name; Op = NEX; Value = obj (); ParameterName = None; Qualifier = None }
/// Specify the name of the parameter for this field
member this.WithParameterName name =
{ this with ParameterName = Some name }
/// Specify a qualifier (alias) for the table from which this field will be referenced
member this.WithQualifier alias =
{ this with Qualifier = Some alias }
/// The required document serialization implementation /// The required document serialization implementation

View File

@ -44,52 +44,80 @@ let all =
Expect.equal field.Name "Test" "Field name incorrect" Expect.equal field.Name "Test" "Field name incorrect"
Expect.equal field.Op EQ "Operator incorrect" Expect.equal field.Op EQ "Operator incorrect"
Expect.equal field.Value 14 "Value incorrect" Expect.equal field.Value 14 "Value incorrect"
Expect.isNone field.ParameterName "The default parameter name should be None"
Expect.isNone field.Qualifier "The default table qualifier should be None"
} }
test "GT succeeds" { test "GT succeeds" {
let field = Field.GT "Great" "night" let field = Field.GT "Great" "night"
Expect.equal field.Name "Great" "Field name incorrect" Expect.equal field.Name "Great" "Field name incorrect"
Expect.equal field.Op GT "Operator incorrect" Expect.equal field.Op GT "Operator incorrect"
Expect.equal field.Value "night" "Value incorrect" Expect.equal field.Value "night" "Value incorrect"
Expect.isNone field.ParameterName "The default parameter name should be None"
Expect.isNone field.Qualifier "The default table qualifier should be None"
} }
test "GE succeeds" { test "GE succeeds" {
let field = Field.GE "Nice" 88L let field = Field.GE "Nice" 88L
Expect.equal field.Name "Nice" "Field name incorrect" Expect.equal field.Name "Nice" "Field name incorrect"
Expect.equal field.Op GE "Operator incorrect" Expect.equal field.Op GE "Operator incorrect"
Expect.equal field.Value 88L "Value incorrect" Expect.equal field.Value 88L "Value incorrect"
Expect.isNone field.ParameterName "The default parameter name should be None"
Expect.isNone field.Qualifier "The default table qualifier should be None"
} }
test "LT succeeds" { test "LT succeeds" {
let field = Field.LT "Lesser" "seven" let field = Field.LT "Lesser" "seven"
Expect.equal field.Name "Lesser" "Field name incorrect" Expect.equal field.Name "Lesser" "Field name incorrect"
Expect.equal field.Op LT "Operator incorrect" Expect.equal field.Op LT "Operator incorrect"
Expect.equal field.Value "seven" "Value incorrect" Expect.equal field.Value "seven" "Value incorrect"
Expect.isNone field.ParameterName "The default parameter name should be None"
Expect.isNone field.Qualifier "The default table qualifier should be None"
} }
test "LE succeeds" { test "LE succeeds" {
let field = Field.LE "Nobody" "KNOWS"; let field = Field.LE "Nobody" "KNOWS";
Expect.equal field.Name "Nobody" "Field name incorrect" Expect.equal field.Name "Nobody" "Field name incorrect"
Expect.equal field.Op LE "Operator incorrect" Expect.equal field.Op LE "Operator incorrect"
Expect.equal field.Value "KNOWS" "Value incorrect" Expect.equal field.Value "KNOWS" "Value incorrect"
Expect.isNone field.ParameterName "The default parameter name should be None"
Expect.isNone field.Qualifier "The default table qualifier should be None"
} }
test "NE succeeds" { test "NE succeeds" {
let field = Field.NE "Park" "here" let field = Field.NE "Park" "here"
Expect.equal field.Name "Park" "Field name incorrect" Expect.equal field.Name "Park" "Field name incorrect"
Expect.equal field.Op NE "Operator incorrect" Expect.equal field.Op NE "Operator incorrect"
Expect.equal field.Value "here" "Value incorrect" Expect.equal field.Value "here" "Value incorrect"
Expect.isNone field.ParameterName "The default parameter name should be None"
Expect.isNone field.Qualifier "The default table qualifier should be None"
} }
test "BT succeeds" { test "BT succeeds" {
let field = Field.BT "Age" 18 49 let field = Field.BT "Age" 18 49
Expect.equal field.Name "Age" "Field name incorrect" Expect.equal field.Name "Age" "Field name incorrect"
Expect.equal field.Op BT "Operator incorrect" Expect.equal field.Op BT "Operator incorrect"
Expect.sequenceEqual (field.Value :?> obj list) [ 18; 49 ] "Value incorrect" Expect.sequenceEqual (field.Value :?> obj list) [ 18; 49 ] "Value incorrect"
Expect.isNone field.ParameterName "The default parameter name should be None"
Expect.isNone field.Qualifier "The default table qualifier should be None"
} }
test "EX succeeds" { test "EX succeeds" {
let field = Field.EX "Groovy" let field = Field.EX "Groovy"
Expect.equal field.Name "Groovy" "Field name incorrect" Expect.equal field.Name "Groovy" "Field name incorrect"
Expect.equal field.Op EX "Operator incorrect" Expect.equal field.Op EX "Operator incorrect"
Expect.isNone field.ParameterName "The default parameter name should be None"
Expect.isNone field.Qualifier "The default table qualifier should be None"
} }
test "NEX succeeds" { test "NEX succeeds" {
let field = Field.NEX "Rad" let field = Field.NEX "Rad"
Expect.equal field.Name "Rad" "Field name incorrect" Expect.equal field.Name "Rad" "Field name incorrect"
Expect.equal field.Op NEX "Operator incorrect" Expect.equal field.Op NEX "Operator incorrect"
Expect.isNone field.ParameterName "The default parameter name should be None"
Expect.isNone field.Qualifier "The default table qualifier should be None"
}
test "WithParameterName succeeds" {
let field = (Field.EQ "Bob" "Tom").WithParameterName "@name"
Expect.isSome field.ParameterName "The parameter name should have been filled"
Expect.equal "@name" field.ParameterName.Value "The parameter name is incorrect"
}
test "WithQualifier succeeds" {
let field = (Field.EQ "Bill" "Matt").WithParameterName "@joe"
Expect.isSome field.Qualifier "The table qualifier should have been filled"
Expect.equal "@joe" field.Qualifier.Value "The table qualifier is incorrect"
} }
] ]
testList "Query" [ testList "Query" [