Question: Method to check it database exists #134

Closed
opened 2025-12-29 15:25:15 +01:00 by adam · 4 comments
Owner

Originally created by @mrichtsfeld on GitHub (May 18, 2017).

Hi @JohnEstropia,

Is there any way to find out if a database already exists before adding it? E.g. I need to do some pre-setup stuff if the user had no database.

Thanks a lot

Originally created by @mrichtsfeld on GitHub (May 18, 2017). Hi @JohnEstropia, Is there any way to find out if a database already exists before adding it? E.g. I need to do some pre-setup stuff if the user had no database. Thanks a lot
adam added the question label 2025-12-29 15:25:15 +01:00
adam closed this issue 2025-12-29 15:25:15 +01:00
Author
Owner

@JohnEstropia commented on GitHub (May 18, 2017):

@mrichtsfeld If you just need to check if the file exists, you can use SQLiteStore to query FileManager:

let storage = SQLiteStore(fileName: "my.sqlite")
if FileManager.default.fileExists(atPath: storage.fileURL.path) {
    // ... pre setup stuff
}
@JohnEstropia commented on GitHub (May 18, 2017): @mrichtsfeld If you just need to check if the file exists, you can use `SQLiteStore` to query `FileManager`: ```swift let storage = SQLiteStore(fileName: "my.sqlite") if FileManager.default.fileExists(atPath: storage.fileURL.path) { // ... pre setup stuff } ```
Author
Owner

@mrichtsfeld commented on GitHub (May 18, 2017):

@JohnEstropia that works perfect for me. Thanks for the hint.

@mrichtsfeld commented on GitHub (May 18, 2017): @JohnEstropia that works perfect for me. Thanks for the hint.
Author
Owner

@HristiyanZahariev commented on GitHub (Jan 22, 2018):

What does pre setup stuff mean? How am I able to use this sqlite database?

@HristiyanZahariev commented on GitHub (Jan 22, 2018): What does pre setup stuff mean? How am I able to use this sqlite database?
Author
Owner

@JohnEstropia commented on GitHub (Jan 22, 2018):

@HristiyanZahariev You can initialize an SQLiteStore with your own file URL:

CoreStore.defaultStack = DataStack(
    xcodeModelName: "Model", // your xcdatamodeld name
    bundle: Bundle(for: type(of: self))
)
try CoreStore.addStorageAndWait(
    SQLiteStore(
        fileURL: yourFileURL // here
    )
)
@JohnEstropia commented on GitHub (Jan 22, 2018): @HristiyanZahariev You can initialize an SQLiteStore with your own file URL: ```swift CoreStore.defaultStack = DataStack( xcodeModelName: "Model", // your xcdatamodeld name bundle: Bundle(for: type(of: self)) ) try CoreStore.addStorageAndWait( SQLiteStore( fileURL: yourFileURL // here ) ) ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#134