Skip to content

Commit f2599c8

Browse files
Add key in ModelProperty errors, add details to log
1 parent 49f7e1a commit f2599c8

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

Sources/Alchemy/SQL/Rune/Model/ModelProperty.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public protocol ModelProperty {
66

77
extension String: ModelProperty {
88
public init(key: String, on row: SQLRowReader) throws {
9-
self = try row.require(key).string()
9+
self = try row.require(key).string(key)
1010
}
1111

1212
public func store(key: String, on row: inout SQLRowWriter) throws {
@@ -16,7 +16,7 @@ extension String: ModelProperty {
1616

1717
extension Bool: ModelProperty {
1818
public init(key: String, on row: SQLRowReader) throws {
19-
self = try row.require(key).bool()
19+
self = try row.require(key).bool(key)
2020
}
2121

2222
public func store(key: String, on row: inout SQLRowWriter) throws {
@@ -26,7 +26,7 @@ extension Bool: ModelProperty {
2626

2727
extension Float: ModelProperty {
2828
public init(key: String, on row: SQLRowReader) throws {
29-
self = Float(try row.require(key).double())
29+
self = Float(try row.require(key).double(key))
3030
}
3131

3232
public func store(key: String, on row: inout SQLRowWriter) throws {
@@ -36,7 +36,7 @@ extension Float: ModelProperty {
3636

3737
extension Double: ModelProperty {
3838
public init(key: String, on row: SQLRowReader) throws {
39-
self = try row.require(key).double()
39+
self = try row.require(key).double(key)
4040
}
4141

4242
public func store(key: String, on row: inout SQLRowWriter) throws {
@@ -46,7 +46,7 @@ extension Double: ModelProperty {
4646

4747
extension FixedWidthInteger {
4848
public init(key: String, on row: SQLRowReader) throws {
49-
self = try .init(row.require(key).int())
49+
self = try .init(row.require(key).int(key))
5050
}
5151

5252
public func store(key: String, on row: inout SQLRowWriter) throws {
@@ -67,7 +67,7 @@ extension UInt64: ModelProperty {}
6767

6868
extension Date: ModelProperty {
6969
public init(key: String, on row: SQLRowReader) throws {
70-
self = try row.require(key).date()
70+
self = try row.require(key).date(key)
7171
}
7272

7373
public func store(key: String, on row: inout SQLRowWriter) throws {
@@ -77,7 +77,7 @@ extension Date: ModelProperty {
7777

7878
extension UUID: ModelProperty {
7979
public init(key: String, on row: SQLRowReader) throws {
80-
self = try row.require(key).uuid()
80+
self = try row.require(key).uuid(key)
8181
}
8282

8383
public func store(key: String, on row: inout SQLRowWriter) throws {

Sources/Alchemy/Utilities/Log.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public struct Log {
2323
/// - message: the message to log.
2424
/// - metadata: any metadata (a typealias of
2525
/// `[String: Logger.MetadataType]`) to log.
26-
public static func trace(_ message: String, metadata: Logger.Metadata? = nil) {
26+
public static func trace(_ message: String, metadata: Logger.Metadata? = nil, file: String = #file, function: String = #function, line: UInt = #line) {
2727
Log.logger.trace(.init(stringLiteral: message), metadata: metadata)
2828
}
2929

@@ -33,8 +33,8 @@ public struct Log {
3333
/// - message: the message to log.
3434
/// - metadata: any metadata (a typealias of
3535
/// `[String: Logger.MetadataType]`) to log.
36-
public static func debug(_ message: String, metadata: Logger.Metadata? = nil) {
37-
Log.logger.debug(.init(stringLiteral: message), metadata: metadata)
36+
public static func debug(_ message: String, metadata: Logger.Metadata? = nil, file: String = #file, function: String = #function, line: UInt = #line) {
37+
Log.logger.debug(.init(stringLiteral: message), metadata: metadata, file: file, function: function, line: line)
3838
}
3939

4040
/// Log a message with the `Logger.Level.info` log level.
@@ -43,8 +43,8 @@ public struct Log {
4343
/// - message: the message to log.
4444
/// - metadata: any metadata (a typealias of
4545
/// `[String: Logger.MetadataType]`) to log.
46-
public static func info(_ message: String, metadata: Logger.Metadata? = nil) {
47-
Log.logger.info(.init(stringLiteral: message), metadata: metadata)
46+
public static func info(_ message: String, metadata: Logger.Metadata? = nil, file: String = #file, function: String = #function, line: UInt = #line) {
47+
Log.logger.info(.init(stringLiteral: message), metadata: metadata, file: file, function: function, line: line)
4848
}
4949

5050
/// Log a message with the `Logger.Level.notice` log level.
@@ -53,8 +53,8 @@ public struct Log {
5353
/// - message: the message to log.
5454
/// - metadata: any metadata (a typealias of
5555
/// `[String: Logger.MetadataType]`) to log.
56-
public static func notice(_ message: String, metadata: Logger.Metadata? = nil) {
57-
Log.logger.notice(.init(stringLiteral: message), metadata: metadata)
56+
public static func notice(_ message: String, metadata: Logger.Metadata? = nil, file: String = #file, function: String = #function, line: UInt = #line) {
57+
Log.logger.notice(.init(stringLiteral: message), metadata: metadata, file: file, function: function, line: line)
5858
}
5959

6060
/// Log a message with the `Logger.Level.warning` log level.
@@ -63,8 +63,8 @@ public struct Log {
6363
/// - message: the message to log.
6464
/// - metadata: any metadata (a typealias of
6565
/// `[String: Logger.MetadataType]`) to log.
66-
public static func warning(_ message: String, metadata: Logger.Metadata? = nil) {
67-
Log.logger.warning(.init(stringLiteral: message), metadata: metadata)
66+
public static func warning(_ message: String, metadata: Logger.Metadata? = nil, file: String = #file, function: String = #function, line: UInt = #line) {
67+
Log.logger.warning(.init(stringLiteral: message), metadata: metadata, file: file, function: function, line: line)
6868
}
6969

7070
/// Log a message with the `Logger.Level.error` log level.
@@ -73,8 +73,8 @@ public struct Log {
7373
/// - message: the message to log.
7474
/// - metadata: any metadata (a typealias of
7575
/// `[String: Logger.MetadataType]`) to log.
76-
public static func error(_ message: String, metadata: Logger.Metadata? = nil) {
77-
Log.logger.error(.init(stringLiteral: message), metadata: metadata)
76+
public static func error(_ message: String, metadata: Logger.Metadata? = nil, file: String = #file, function: String = #function, line: UInt = #line) {
77+
Log.logger.error(.init(stringLiteral: message), metadata: metadata, file: file, function: function, line: line)
7878
}
7979

8080
/// Log a message with the `Logger.Level.critical` log level.
@@ -83,7 +83,7 @@ public struct Log {
8383
/// - message: the message to log.
8484
/// - metadata: any metadata (a typealias of
8585
/// `[String: Logger.MetadataType]`) to log.
86-
public static func critical(_ message: String, metadata: Logger.Metadata? = nil) {
87-
Log.logger.critical(.init(stringLiteral: message), metadata: metadata)
86+
public static func critical(_ message: String, metadata: Logger.Metadata? = nil, file: String = #file, function: String = #function, line: UInt = #line) {
87+
Log.logger.critical(.init(stringLiteral: message), metadata: metadata, file: file, function: function, line: line)
8888
}
8989
}

0 commit comments

Comments
 (0)