Skip to content

Commit 532a377

Browse files
committed
Make aggregate function shims private
Signed-off-by: Stephen Celis <stephen@stephencelis.com>
1 parent 610138e commit 532a377

File tree

2 files changed

+61
-59
lines changed

2 files changed

+61
-59
lines changed

SQLite/Expression.swift

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -719,45 +719,6 @@ public func total<V: Value where V.Datatype: Number>(expression: Expression<V?>)
719719
public func total<V: Value where V.Datatype: Number>(#distinct: Expression<V>) -> Expression<Double> { return wrapDistinct("total", distinct) }
720720
public func total<V: Value where V.Datatype: Number>(#distinct: Expression<V?>) -> Expression<Double> { return wrapDistinct("total", distinct) }
721721

722-
internal func SQLite_count<V: Value>(expression: Expression<V?>) -> Expression<Int> { return count(expression) }
723-
724-
internal func SQLite_count<V: Value>(#distinct: Expression<V>) -> Expression<Int> { return count(distinct: distinct) }
725-
internal func SQLite_count<V: Value>(#distinct: Expression<V?>) -> Expression<Int> { return count(distinct: distinct) }
726-
727-
internal func SQLite_count(star: Star) -> Expression<Int> { return count(star) }
728-
729-
internal func SQLite_max<V: Value where V.Datatype: Comparable>(expression: Expression<V>) -> Expression<V?> {
730-
return max(expression)
731-
}
732-
internal func SQLite_max<V: Value where V.Datatype: Comparable>(expression: Expression<V?>) -> Expression<V?> {
733-
return max(expression)
734-
}
735-
736-
internal func SQLite_min<V: Value where V.Datatype: Comparable>(expression: Expression<V>) -> Expression<V?> {
737-
return min(expression)
738-
}
739-
internal func SQLite_min<V: Value where V.Datatype: Comparable>(expression: Expression<V?>) -> Expression<V?> {
740-
return min(expression)
741-
}
742-
743-
internal func SQLite_average<V: Value where V.Datatype: Number>(expression: Expression<V>) -> Expression<Double?> { return average(expression) }
744-
internal func SQLite_average<V: Value where V.Datatype: Number>(expression: Expression<V?>) -> Expression<Double?> { return average(expression) }
745-
746-
internal func SQLite_average<V: Value where V.Datatype: Number>(#distinct: Expression<V>) -> Expression<Double?> { return average(distinct: distinct) }
747-
internal func SQLite_average<V: Value where V.Datatype: Number>(#distinct: Expression<V?>) -> Expression<Double?> { return average(distinct: distinct) }
748-
749-
internal func SQLite_sum<V: Value where V.Datatype: Number>(expression: Expression<V>) -> Expression<V?> { return sum(expression) }
750-
internal func SQLite_sum<V: Value where V.Datatype: Number>(expression: Expression<V?>) -> Expression<V?> { return sum(expression) }
751-
752-
internal func SQLite_sum<V: Value where V.Datatype: Number>(#distinct: Expression<V>) -> Expression<V?> { return sum(distinct: distinct) }
753-
internal func SQLite_sum<V: Value where V.Datatype: Number>(#distinct: Expression<V?>) -> Expression<V?> { return sum(distinct: distinct) }
754-
755-
internal func SQLite_total<V: Value where V.Datatype: Number>(expression: Expression<V>) -> Expression<Double> { return total(expression) }
756-
internal func SQLite_total<V: Value where V.Datatype: Number>(expression: Expression<V?>) -> Expression<Double> { return total(expression) }
757-
758-
internal func SQLite_total<V: Value where V.Datatype: Number>(#distinct: Expression<V>) -> Expression<Double> { return total(distinct: distinct) }
759-
internal func SQLite_total<V: Value where V.Datatype: Number>(#distinct: Expression<V?>) -> Expression<Double> { return total(distinct: distinct) }
760-
761722
private func wrapDistinct<V, U>(function: String, expression: Expression<V>) -> Expression<U> {
762723
return wrap(function, Expression<()>.join(" ", [Expression<()>(literal: "DISTINCT"), expression]))
763724
}

SQLite/Query.swift

Lines changed: 61 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ public struct Query {
597597
///
598598
/// :returns: The number of rows matching the given column.
599599
public func count<V: Value>(column: Expression<V?>) -> Int {
600-
return calculate(SQLite_count(column))!
600+
return calculate(_count(column))!
601601
}
602602

603603
/// Runs count() with DISTINCT against the query.
@@ -606,7 +606,7 @@ public struct Query {
606606
///
607607
/// :returns: The number of rows matching the given column.
608608
public func count<V: Value>(distinct column: Expression<V>) -> Int {
609-
return calculate(SQLite_count(distinct: column))!
609+
return calculate(_count(distinct: column))!
610610
}
611611

612612
/// Runs count() with DISTINCT against the query.
@@ -615,7 +615,7 @@ public struct Query {
615615
///
616616
/// :returns: The number of rows matching the given column.
617617
public func count<V: Value>(distinct column: Expression<V?>) -> Int {
618-
return calculate(SQLite_count(distinct: column))!
618+
return calculate(_count(distinct: column))!
619619
}
620620

621621
/// Runs max() against the query.
@@ -624,10 +624,10 @@ public struct Query {
624624
///
625625
/// :returns: The largest value of the given column.
626626
public func max<V: Value where V.Datatype: Comparable>(column: Expression<V>) -> V? {
627-
return calculate(SQLite_max(column))
627+
return calculate(_max(column))
628628
}
629629
public func max<V: Value where V.Datatype: Comparable>(column: Expression<V?>) -> V? {
630-
return calculate(SQLite_max(column))
630+
return calculate(_max(column))
631631
}
632632

633633
/// Runs min() against the query.
@@ -636,10 +636,10 @@ public struct Query {
636636
///
637637
/// :returns: The smallest value of the given column.
638638
public func min<V: Value where V.Datatype: Comparable>(column: Expression<V>) -> V? {
639-
return calculate(SQLite_min(column))
639+
return calculate(_min(column))
640640
}
641641
public func min<V: Value where V.Datatype: Comparable>(column: Expression<V?>) -> V? {
642-
return calculate(SQLite_min(column))
642+
return calculate(_min(column))
643643
}
644644

645645
/// Runs avg() against the query.
@@ -648,10 +648,10 @@ public struct Query {
648648
///
649649
/// :returns: The average value of the given column.
650650
public func average<V: Value where V.Datatype: Number>(column: Expression<V>) -> Double? {
651-
return calculate(SQLite_average(column))
651+
return calculate(_average(column))
652652
}
653653
public func average<V: Value where V.Datatype: Number>(column: Expression<V?>) -> Double? {
654-
return calculate(SQLite_average(column))
654+
return calculate(_average(column))
655655
}
656656

657657
/// Runs avg() with DISTINCT against the query.
@@ -660,10 +660,10 @@ public struct Query {
660660
///
661661
/// :returns: The average value of the given column.
662662
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))
664664
}
665665
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))
667667
}
668668

669669
/// Runs sum() against the query.
@@ -672,10 +672,10 @@ public struct Query {
672672
///
673673
/// :returns: The sum of the given column’s values.
674674
public func sum<V: Value where V.Datatype: Number>(column: Expression<V>) -> V? {
675-
return calculate(SQLite_sum(column))
675+
return calculate(_sum(column))
676676
}
677677
public func sum<V: Value where V.Datatype: Number>(column: Expression<V?>) -> V? {
678-
return calculate(SQLite_sum(column))
678+
return calculate(_sum(column))
679679
}
680680

681681
/// Runs sum() with DISTINCT against the query.
@@ -684,10 +684,10 @@ public struct Query {
684684
///
685685
/// :returns: The sum of the given column’s values.
686686
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))
688688
}
689689
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))
691691
}
692692

693693
/// Runs total() against the query.
@@ -696,10 +696,10 @@ public struct Query {
696696
///
697697
/// :returns: The total of the given column’s values.
698698
public func total<V: Value where V.Datatype: Number>(column: Expression<V>) -> Double {
699-
return calculate(SQLite_total(column))!
699+
return calculate(_total(column))!
700700
}
701701
public func total<V: Value where V.Datatype: Number>(column: Expression<V?>) -> Double {
702-
return calculate(SQLite_total(column))!
702+
return calculate(_total(column))!
703703
}
704704

705705
/// Runs total() with DISTINCT against the query.
@@ -708,10 +708,10 @@ public struct Query {
708708
///
709709
/// :returns: The total of the given column’s values.
710710
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))!
712712
}
713713
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))!
715715
}
716716

717717
private func calculate<V: Value>(expression: Expression<V>) -> V? {
@@ -724,7 +724,7 @@ public struct Query {
724724
// MARK: - Array
725725

726726
/// 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(*))! }
728728

729729
/// Returns true if the query has no rows.
730730
public var isEmpty: Bool { return first == nil }
@@ -880,3 +880,44 @@ extension Database {
880880
}
881881

882882
}
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

Comments
 (0)