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

Dump requests #1439

Merged
merged 6 commits into from
Oct 12, 2023
Merged

Dump requests #1439

merged 6 commits into from
Oct 12, 2023

Conversation

groue
Copy link
Owner

@groue groue commented Oct 8, 2023

This PR brings the dump family of methods, suited for use in the debugger, or testing:

// Prints the full database content
try dbQueue.dumpContent()

// Prints the content of provided tables
try dbQueue.dumpTables(["player", "team"])

// Prints the content of a request
try dbQueue.dumpRequest(Player.all())

// Prints the content of SQL queries
try dbQueue.dumpSQL("SELECT * FROM player")

// Same printing methods exist on Database:
try dbQueue.read { db in
    try db.dumpContent()
    try db.dumpTables(["player", "team"])
    try db.dumpRequest(Player.all())
    try db.dumpSQL("SELECT * FROM player")
}

Several output formats are built-in, inspired by SQLite command-line tool:

// Prints one database row per line.
// The `.debug` format is suited for debugging, but not for testing.
// It may evolve over time in order to further help developers.
try dbQueue.dumpRequest(Player.all())
try dbQueue.dumpRequest(Player.all(), format: .debug())

// Prints one database value per line. All blob values are interpreted as strings.
try dbQueue.dumpRequest(Player.all(), format: .line())

// Prints one database row per line. All blob values are interpreted as strings.
try dbQueue.dumpRequest(Player.all(), format: .list())

// Prints one database row per line, formatting values as SQL literals.
try dbQueue.dumpRequest(Player.all(), format: .quote())

// Who doesn't like JSON?
try dbQueue.dumpRequest(Player.all(), format: .json())

It is just so handy to be able to dump database content at will!

Capture d’écran 2023-10-08 à 21 15 11

@groue groue force-pushed the dev/dump branch 19 times, most recently from 6ec12e0 to efa6c8c Compare October 12, 2023 06:18
@groue groue merged commit 856d9cb into development Oct 12, 2023
22 checks passed
@groue groue deleted the dev/dump branch October 12, 2023 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant