@@ -597,7 +597,7 @@ public struct Query {
597
597
///
598
598
/// :returns: The number of rows matching the given column.
599
599
public func count< V: Value > ( column: Expression < V ? > ) -> Int {
600
- return calculate ( SQLite_count ( column) ) !
600
+ return calculate ( _count ( column) ) !
601
601
}
602
602
603
603
/// Runs count() with DISTINCT against the query.
@@ -606,7 +606,7 @@ public struct Query {
606
606
///
607
607
/// :returns: The number of rows matching the given column.
608
608
public func count< V: Value > ( distinct column: Expression < V > ) -> Int {
609
- return calculate ( SQLite_count ( distinct: column) ) !
609
+ return calculate ( _count ( distinct: column) ) !
610
610
}
611
611
612
612
/// Runs count() with DISTINCT against the query.
@@ -615,7 +615,7 @@ public struct Query {
615
615
///
616
616
/// :returns: The number of rows matching the given column.
617
617
public func count< V: Value > ( distinct column: Expression < V ? > ) -> Int {
618
- return calculate ( SQLite_count ( distinct: column) ) !
618
+ return calculate ( _count ( distinct: column) ) !
619
619
}
620
620
621
621
/// Runs max() against the query.
@@ -624,10 +624,10 @@ public struct Query {
624
624
///
625
625
/// :returns: The largest value of the given column.
626
626
public func max< V: Value where V. Datatype: Comparable > ( column: Expression < V > ) -> V ? {
627
- return calculate ( SQLite_max ( column) )
627
+ return calculate ( _max ( column) )
628
628
}
629
629
public func max< V: Value where V. Datatype: Comparable > ( column: Expression < V ? > ) -> V ? {
630
- return calculate ( SQLite_max ( column) )
630
+ return calculate ( _max ( column) )
631
631
}
632
632
633
633
/// Runs min() against the query.
@@ -636,10 +636,10 @@ public struct Query {
636
636
///
637
637
/// :returns: The smallest value of the given column.
638
638
public func min< V: Value where V. Datatype: Comparable > ( column: Expression < V > ) -> V ? {
639
- return calculate ( SQLite_min ( column) )
639
+ return calculate ( _min ( column) )
640
640
}
641
641
public func min< V: Value where V. Datatype: Comparable > ( column: Expression < V ? > ) -> V ? {
642
- return calculate ( SQLite_min ( column) )
642
+ return calculate ( _min ( column) )
643
643
}
644
644
645
645
/// Runs avg() against the query.
@@ -648,10 +648,10 @@ public struct Query {
648
648
///
649
649
/// :returns: The average value of the given column.
650
650
public func average< V: Value where V. Datatype: Number > ( column: Expression < V > ) -> Double ? {
651
- return calculate ( SQLite_average ( column) )
651
+ return calculate ( _average ( column) )
652
652
}
653
653
public func average< V: Value where V. Datatype: Number > ( column: Expression < V ? > ) -> Double ? {
654
- return calculate ( SQLite_average ( column) )
654
+ return calculate ( _average ( column) )
655
655
}
656
656
657
657
/// Runs avg() with DISTINCT against the query.
@@ -660,10 +660,10 @@ public struct Query {
660
660
///
661
661
/// :returns: The average value of the given column.
662
662
public func average< V: Value where V. Datatype: Number > ( distinct column: Expression < V > ) -> Double ? {
663
- return calculate ( SQLite_average ( distinct: column) )
663
+ return calculate ( _average ( distinct: column) )
664
664
}
665
665
public func average< V: Value where V. Datatype: Number > ( distinct column: Expression < V ? > ) -> Double ? {
666
- return calculate ( SQLite_average ( distinct: column) )
666
+ return calculate ( _average ( distinct: column) )
667
667
}
668
668
669
669
/// Runs sum() against the query.
@@ -672,10 +672,10 @@ public struct Query {
672
672
///
673
673
/// :returns: The sum of the given column’s values.
674
674
public func sum< V: Value where V. Datatype: Number > ( column: Expression < V > ) -> V ? {
675
- return calculate ( SQLite_sum ( column) )
675
+ return calculate ( _sum ( column) )
676
676
}
677
677
public func sum< V: Value where V. Datatype: Number > ( column: Expression < V ? > ) -> V ? {
678
- return calculate ( SQLite_sum ( column) )
678
+ return calculate ( _sum ( column) )
679
679
}
680
680
681
681
/// Runs sum() with DISTINCT against the query.
@@ -684,10 +684,10 @@ public struct Query {
684
684
///
685
685
/// :returns: The sum of the given column’s values.
686
686
public func sum< V: Value where V. Datatype: Number > ( distinct column: Expression < V > ) -> V ? {
687
- return calculate ( SQLite_sum ( distinct: column) )
687
+ return calculate ( _sum ( distinct: column) )
688
688
}
689
689
public func sum< V: Value where V. Datatype: Number > ( distinct column: Expression < V ? > ) -> V ? {
690
- return calculate ( SQLite_sum ( distinct: column) )
690
+ return calculate ( _sum ( distinct: column) )
691
691
}
692
692
693
693
/// Runs total() against the query.
@@ -696,10 +696,10 @@ public struct Query {
696
696
///
697
697
/// :returns: The total of the given column’s values.
698
698
public func total< V: Value where V. Datatype: Number > ( column: Expression < V > ) -> Double {
699
- return calculate ( SQLite_total ( column) ) !
699
+ return calculate ( _total ( column) ) !
700
700
}
701
701
public func total< V: Value where V. Datatype: Number > ( column: Expression < V ? > ) -> Double {
702
- return calculate ( SQLite_total ( column) ) !
702
+ return calculate ( _total ( column) ) !
703
703
}
704
704
705
705
/// Runs total() with DISTINCT against the query.
@@ -708,10 +708,10 @@ public struct Query {
708
708
///
709
709
/// :returns: The total of the given column’s values.
710
710
public func total< V: Value where V. Datatype: Number > ( distinct column: Expression < V > ) -> Double {
711
- return calculate ( SQLite_total ( distinct: column) ) !
711
+ return calculate ( _total ( distinct: column) ) !
712
712
}
713
713
public func total< V: Value where V. Datatype: Number > ( distinct column: Expression < V ? > ) -> Double {
714
- return calculate ( SQLite_total ( distinct: column) ) !
714
+ return calculate ( _total ( distinct: column) ) !
715
715
}
716
716
717
717
private func calculate< V: Value > ( expression: Expression < V > ) -> V ? {
@@ -724,7 +724,7 @@ public struct Query {
724
724
// MARK: - Array
725
725
726
726
/// Runs count(*) against the query and returns it.
727
- public var count : Int { return calculate ( SQLite_count ( * ) ) ! }
727
+ public var count : Int { return calculate ( _count ( * ) ) ! }
728
728
729
729
/// Returns true if the query has no rows.
730
730
public var isEmpty : Bool { return first == nil }
@@ -880,3 +880,44 @@ extension Database {
880
880
}
881
881
882
882
}
883
+
884
+ // Private shims provide frameworkless support by avoiding the SQLite module namespace.
885
+
886
+ private func _count< V: Value > ( expression: Expression < V ? > ) -> Expression < Int > { return count ( expression) }
887
+
888
+ private func _count< V: Value > ( #distinct: Expression< V> ) -> Expression< Int> { return count ( distinct: distinct) }
889
+ private func _count< V: Value > ( #distinct: Expression< V?>) -> Expression < Int > { return count ( distinct: distinct) }
890
+
891
+ private func _count( star: Star ) -> Expression < Int > { return count ( star) }
892
+
893
+ private func _max< V: Value where V. Datatype: Comparable > ( expression: Expression < V > ) -> Expression < V ? > {
894
+ return max ( expression)
895
+ }
896
+ private func _max< V: Value where V. Datatype: Comparable > ( expression: Expression < V ? > ) -> Expression < V ? > {
897
+ return max ( expression)
898
+ }
899
+
900
+ private func _min< V: Value where V. Datatype: Comparable > ( expression: Expression < V > ) -> Expression < V ? > {
901
+ return min ( expression)
902
+ }
903
+ private func _min< V: Value where V. Datatype: Comparable > ( expression: Expression < V ? > ) -> Expression < V ? > {
904
+ return min ( expression)
905
+ }
906
+
907
+ private func _average< V: Value where V. Datatype: Number > ( expression: Expression < V > ) -> Expression < Double ? > { return average ( expression) }
908
+ private func _average< V: Value where V. Datatype: Number > ( expression: Expression < V ? > ) -> Expression < Double ? > { return average ( expression) }
909
+
910
+ private func _average< V: Value where V. Datatype: Number > ( #distinct: Expression< V> ) -> Expression< Double? > { return average( distinct: distinct ) }
911
+ private func _average< V: Value where V. Datatype: Number > ( #distinct: Expression< V?>) -> Expression < Double ? > { return average ( distinct: distinct) }
912
+
913
+ private func _sum< V: Value where V. Datatype: Number > ( expression: Expression < V > ) -> Expression < V ? > { return sum ( expression) }
914
+ private func _sum< V: Value where V. Datatype: Number > ( expression: Expression < V ? > ) -> Expression < V ? > { return sum ( expression) }
915
+
916
+ private func _sum< V: Value where V. Datatype: Number > ( #distinct: Expression< V> ) -> Expression< V? > { return sum( distinct: distinct ) }
917
+ private func _sum< V: Value where V. Datatype: Number > ( #distinct: Expression< V?>) -> Expression < V ? > { return sum ( distinct: distinct) }
918
+
919
+ private func _total< V: Value where V. Datatype: Number > ( expression: Expression < V > ) -> Expression < Double > { return total ( expression) }
920
+ private func _total< V: Value where V. Datatype: Number > ( expression: Expression < V ? > ) -> Expression < Double > { return total ( expression) }
921
+
922
+ private func _total< V: Value where V. Datatype: Number > ( #distinct: Expression< V> ) -> Expression< Double> { return total( distinct: distinct ) }
923
+ private func _total< V: Value where V. Datatype: Number > ( #distinct: Expression< V?>) -> Expression < Double > { return total ( distinct: distinct) }
0 commit comments