Created
May 24, 2020 15:25
-
-
Save littlebobert/01ebfc585b780c173f34f3b7796664a9 to your computer and use it in GitHub Desktop.
Adding records to my Movie table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// I have one table: Movie. To add records, after the Movie migration I’m doing: | |
let worker = MultiThreadedEventLoopGroup(numberOfThreads: 1) | |
let conn = sqliteDatabase.newConnection(on: worker) | |
let _ = conn.map { connection in | |
// Open the CSV file | |
for line in lines { | |
// Parse the line to get the title, etc. | |
let movie = Movie(id: id, title: title) | |
dispatchGroup.enter() | |
let future = movie.save(on: connection) | |
future.whenFailure { (error) in | |
dispatchGroup.leave() | |
} | |
future.whenSuccess { _ in | |
dispatchGroup.leave() | |
} | |
// ...etc. | |
} | |
dispatchGroup.notify(queue: .global()) { | |
worker.shutdownGracefully { error in | |
// etc. | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To figure out when migrations are finished, I’m doing: