Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve foreign key support #133

Merged
merged 2 commits into from
May 30, 2018
Merged

Improve foreign key support #133

merged 2 commits into from
May 30, 2018

Conversation

kilnerm
Copy link
Contributor

@kilnerm kilnerm commented May 11, 2018

This PR improves Swift-Kuery's support for foreign keys.

With the changes it is now possible to specify multiple foreign keys on a table.

It should be noted that a user will still need to ensure their tables are built correctly to allow the use of composite keys.

@codecov-io
Copy link

codecov-io commented May 11, 2018

Codecov Report

Merging #133 into master will decrease coverage by 0.04%.
The diff coverage is 86.15%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #133      +/-   ##
==========================================
- Coverage   84.49%   84.45%   -0.05%     
==========================================
  Files          43       44       +1     
  Lines        3606     3641      +35     
==========================================
+ Hits         3047     3075      +28     
- Misses        559      566       +7
Flag Coverage Δ
#SwiftKuery 84.45% <86.15%> (-0.05%) ⬇️
Impacted Files Coverage Δ
Sources/SwiftKuery/Table.swift 82% <100%> (+0.01%) ⬆️
Sources/SwiftKuery/ForeignKey.swift 80.43% <80.43%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d48a2ad...9a7f28b. Read the comment docs.

Copy link
Contributor

@Andrew-Lees11 Andrew-Lees11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really Like the refactoring in this request and the tests added look good.
Few comments about docs etc but otherwise looks good

/// Function that returns the SQL CREATE TABLE query as a String for this TABLE.
/// - Returns: A String representation of the table create statement.
/// - Throws: QueryError.syntaxError if statement build fails.
public func description(connection: Connection) throws -> String {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a reason you moved the describe to the bottom of the class? Just thinking in terms of Jazzy docs since descriptions kind of fits within Initializer?

```swift
public class EmployeeTable: Table {
let tableName = "employeeTable"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were you intending to change these from 4 to 3 spaces? Clogs up the diff a bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation in the two tables in the documentation was a space out, I'll change this and make them both consistent to 4 spaces.

if !foreignKeys.contains(newKey) {
foreignKeys.append(newKey)
} else {
print("Duplicate foreign key detected")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is a print because we still want to continue if we detect duplicate foreign keys. Do we want this to be a log instead of a print through?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was debug I had missed during my tidy up, will remove it.

return true
}

/// Function that returns the SQL CREATE TABLE query as a String for this TABLE.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really you but could you add a Usage example to the jazzy docs here since you understand this and are currently editing this section?

var t2 = Table2()

// This tests a one to one foreign key
var createStmt = createTable(t1.foreignKey(t1.a, references: t2.b), connection: connection)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The names t1.a are not very helpful for understanding the tests but i realize that you have done this to be consistent with the other tests. Maybe we need another PR to rename all the tests so they can be read more easily

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the tests would benefit from a bit of an overhaul in future. I can raise an issue.

@kilnerm kilnerm force-pushed the issue_806 branch 3 times, most recently from 85f3add to 2b81aba Compare May 17, 2018 08:22
// Prints CREATE TABLE ExampleTable (name text)
```

/// - Returns: A String representation of the table create statement.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these are inside the multiline comment they don't need comment lines here and don't display properly in Jazzy.

Copy link
Contributor

@Andrew-Lees11 Andrew-Lees11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

return true
}

func describe(queryBuilder: QueryBuilder) -> String {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An idea: should we follow the Buidable format and make this the build method?

}
keyColumns = keys
refColumns = refs
keyNames = keyColumns.map { "\($0._table._name).\($0.name)"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue with spaces

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I corrected the spaces at the end of the closure.

If you were referring to the need to pack its unnecessary here as these values will not be used in sql statements.

@EnriqueL8 EnriqueL8 merged commit 2a6fb7a into master May 30, 2018
@EnriqueL8 EnriqueL8 deleted the issue_806 branch May 30, 2018 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants