Skip to content

Commit bfca5f2

Browse files
committed
Rename name to tableName
1 parent 2b96b48 commit bfca5f2

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

Sources/Basics/SQLiteBackedCache.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import TSCUtility
1717
public final class SQLiteBackedCache<Value: Codable>: Closable {
1818
public typealias Key = String
1919

20-
public let name: String
20+
public let tableName: String
2121
public let fileSystem: TSCBasic.FileSystem
2222
public let location: SQLite.Location
2323
public let configuration: SQLiteBackedCacheConfiguration
@@ -29,8 +29,8 @@ public final class SQLiteBackedCache<Value: Codable>: Closable {
2929
private let jsonEncoder: JSONEncoder
3030
private let jsonDecoder: JSONDecoder
3131

32-
public init(name: String, location: SQLite.Location, configuration: SQLiteBackedCacheConfiguration = .init(), diagnosticsEngine: DiagnosticsEngine? = nil) {
33-
self.name = name
32+
public init(tableName: String, location: SQLite.Location, configuration: SQLiteBackedCacheConfiguration = .init(), diagnosticsEngine: DiagnosticsEngine? = nil) {
33+
self.tableName = tableName
3434
self.location = location
3535
switch self.location {
3636
case .path, .temporary:
@@ -44,8 +44,8 @@ public final class SQLiteBackedCache<Value: Codable>: Closable {
4444
self.jsonDecoder = JSONDecoder.makeWithDefaults()
4545
}
4646

47-
public convenience init(name: String, path: AbsolutePath, configuration: SQLiteBackedCacheConfiguration = .init(), diagnosticsEngine: DiagnosticsEngine? = nil) {
48-
self.init(name: name, location: .path(path), configuration: configuration, diagnosticsEngine: diagnosticsEngine)
47+
public convenience init(tableName: String, path: AbsolutePath, configuration: SQLiteBackedCacheConfiguration = .init(), diagnosticsEngine: DiagnosticsEngine? = nil) {
48+
self.init(tableName: tableName, location: .path(path), configuration: configuration, diagnosticsEngine: diagnosticsEngine)
4949
}
5050

5151
deinit {
@@ -69,7 +69,7 @@ public final class SQLiteBackedCache<Value: Codable>: Closable {
6969

7070
public func put(key: Key, value: Value, replace: Bool = false) throws {
7171
do {
72-
let query = "INSERT OR \(replace ? "REPLACE" : "IGNORE") INTO \(self.name) VALUES (?, ?);"
72+
let query = "INSERT OR \(replace ? "REPLACE" : "IGNORE") INTO \(self.tableName) VALUES (?, ?);"
7373
try self.executeStatement(query) { statement -> Void in
7474
let data = try self.jsonEncoder.encode(value)
7575
let bindings: [SQLite.SQLiteValue] = [
@@ -83,8 +83,8 @@ public final class SQLiteBackedCache<Value: Codable>: Closable {
8383
if !self.configuration.truncateWhenFull {
8484
throw error
8585
}
86-
self.diagnosticsEngine?.emit(.warning("truncating \(self.name) cache database since it reached max size of \(self.configuration.maxSizeInBytes ?? 0) bytes"))
87-
try self.executeStatement("DELETE FROM \(self.name);") { statement -> Void in
86+
self.diagnosticsEngine?.emit(.warning("truncating \(self.tableName) cache database since it reached max size of \(self.configuration.maxSizeInBytes ?? 0) bytes"))
87+
try self.executeStatement("DELETE FROM \(self.tableName);") { statement -> Void in
8888
try statement.step()
8989
}
9090
try self.put(key: key, value: value, replace: replace)
@@ -94,7 +94,7 @@ public final class SQLiteBackedCache<Value: Codable>: Closable {
9494
}
9595

9696
public func get(key: Key) throws -> Value? {
97-
let query = "SELECT value FROM \(self.name) WHERE key = ? LIMIT 1;"
97+
let query = "SELECT value FROM \(self.tableName) WHERE key = ? LIMIT 1;"
9898
return try self.executeStatement(query) { statement -> Value? in
9999
try statement.bind([.string(key)])
100100
let data = try statement.step()?.blob(at: 0)
@@ -105,7 +105,7 @@ public final class SQLiteBackedCache<Value: Codable>: Closable {
105105
}
106106

107107
public func remove(key: Key) throws {
108-
let query = "DELETE FROM \(self.name) WHERE key = ? LIMIT 1;"
108+
let query = "DELETE FROM \(self.tableName) WHERE key = ? LIMIT 1;"
109109
try self.executeStatement(query) { statement in
110110
try statement.bind([.string(key)])
111111
try statement.step()
@@ -175,7 +175,7 @@ public final class SQLiteBackedCache<Value: Codable>: Closable {
175175

176176
private func createSchemaIfNecessary(db: SQLite) throws {
177177
let table = """
178-
CREATE TABLE IF NOT EXISTS \(self.name) (
178+
CREATE TABLE IF NOT EXISTS \(self.tableName) (
179179
key STRING PRIMARY KEY NOT NULL,
180180
value BLOB NOT NULL
181181
);

Sources/PackageCollections/Providers/GitHubPackageMetadataProvider.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct GitHubPackageMetadataProvider: PackageMetadataProvider {
3737
if configuration.cacheTTLInSeconds > 0 {
3838
var cacheConfig = SQLiteBackedCacheConfiguration()
3939
cacheConfig.maxSizeInMegabytes = configuration.cacheSizeInMegabytes
40-
self.cache = SQLiteBackedCache<CacheValue>(name: "github_cache", path: configuration.cacheDir.appending(component: "package-metadata.db"), configuration: cacheConfig, diagnosticsEngine: diagnosticsEngine)
40+
self.cache = SQLiteBackedCache<CacheValue>(tableName: "github_cache", path: configuration.cacheDir.appending(component: "package-metadata.db"), configuration: cacheConfig, diagnosticsEngine: diagnosticsEngine)
4141
} else {
4242
self.cache = nil
4343
}

Sources/PackageLoading/ManifestLoader.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
4+
Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See http://swift.org/LICENSE.txt for license information
@@ -591,7 +591,7 @@ public final class ManifestLoader: ManifestLoaderProtocol {
591591
// FIXME: expose as user-facing configuration
592592
configuration.maxSizeInMegabytes = 100
593593
configuration.truncateWhenFull = true
594-
return SQLiteBackedCache<ManifestParseResult>(name: "MANIFEST_CACHE", location: .path(path), configuration: configuration, diagnosticsEngine: diagnostics)
594+
return SQLiteBackedCache<ManifestParseResult>(tableName: "MANIFEST_CACHE", location: .path(path), configuration: configuration, diagnosticsEngine: diagnostics)
595595
}
596596

597597
// TODO: we could wrap the failure here with diagnostics if it wasn't optional throughout

Tests/BasicsTests/SQLiteBackedCacheTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ final class SQLiteBackedCacheTests: XCTestCase {
1818
func testHappyCase() throws {
1919
try testWithTemporaryDirectory { tmpPath in
2020
let path = tmpPath.appending(component: "test.db")
21-
let cache = SQLiteBackedCache<String>(name: "SQLiteBackedCacheTest", path: path)
21+
let cache = SQLiteBackedCache<String>(tableName: "SQLiteBackedCacheTest", path: path)
2222
defer { XCTAssertNoThrow(try cache.close()) }
2323

2424
let mockData = try makeMockData(fileSystem: localFileSystem, rootPath: tmpPath)
@@ -53,7 +53,7 @@ final class SQLiteBackedCacheTests: XCTestCase {
5353
func testFileDeleted() throws {
5454
try testWithTemporaryDirectory { tmpPath in
5555
let path = tmpPath.appending(component: "test.db")
56-
let cache = SQLiteBackedCache<String>(name: "SQLiteBackedCacheTest", path: path)
56+
let cache = SQLiteBackedCache<String>(tableName: "SQLiteBackedCacheTest", path: path)
5757
defer { XCTAssertNoThrow(try cache.close()) }
5858

5959
let mockData = try makeMockData(fileSystem: localFileSystem, rootPath: tmpPath)
@@ -93,7 +93,7 @@ final class SQLiteBackedCacheTests: XCTestCase {
9393
func testFileCorrupt() throws {
9494
try testWithTemporaryDirectory { tmpPath in
9595
let path = tmpPath.appending(component: "test.db")
96-
let cache = SQLiteBackedCache<String>(name: "SQLiteBackedCacheTest", path: path)
96+
let cache = SQLiteBackedCache<String>(tableName: "SQLiteBackedCacheTest", path: path)
9797
defer { XCTAssertNoThrow(try cache.close()) }
9898

9999
let mockData = try makeMockData(fileSystem: localFileSystem, rootPath: tmpPath)
@@ -131,7 +131,7 @@ final class SQLiteBackedCacheTests: XCTestCase {
131131
var configuration = SQLiteBackedCacheConfiguration()
132132
configuration.maxSizeInBytes = 1024 * 3
133133
configuration.truncateWhenFull = false
134-
let cache = SQLiteBackedCache<String>(name: "SQLiteBackedCacheTest", path: path, configuration: configuration)
134+
let cache = SQLiteBackedCache<String>(tableName: "SQLiteBackedCacheTest", path: path, configuration: configuration)
135135
defer { XCTAssertNoThrow(try cache.close()) }
136136

137137
func create() throws {
@@ -153,7 +153,7 @@ final class SQLiteBackedCacheTests: XCTestCase {
153153
var configuration = SQLiteBackedCacheConfiguration()
154154
configuration.maxSizeInBytes = 1024 * 3
155155
configuration.truncateWhenFull = true
156-
let cache = SQLiteBackedCache<String>(name: "SQLiteBackedCacheTest", path: path, configuration: configuration)
156+
let cache = SQLiteBackedCache<String>(tableName: "SQLiteBackedCacheTest", path: path, configuration: configuration)
157157
defer { XCTAssertNoThrow(try cache.close()) }
158158

159159
var keys = [String]()

Tests/PackageLoadingTests/ManifestLoaderSQLiteCacheTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ManifestLoaderSQLiteCacheTests: XCTestCase {
2020
func testHappyCase() throws {
2121
try testWithTemporaryDirectory { tmpPath in
2222
let path = tmpPath.appending(component: "test.db")
23-
let storage = SQLiteBackedCache<ManifestLoader.ManifestParseResult>(name: "manifests", path: path)
23+
let storage = SQLiteBackedCache<ManifestLoader.ManifestParseResult>(tableName: "manifests", path: path)
2424
defer { XCTAssertNoThrow(try storage.close()) }
2525

2626
let mockManifests = try makeMockManifests(fileSystem: localFileSystem, rootPath: tmpPath)

0 commit comments

Comments
 (0)