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

Run without an active database #1606

Closed
jneumann opened this Issue Mar 29, 2018 · 4 comments

Comments

Projects
None yet
3 participants
@jneumann

jneumann commented Mar 29, 2018

I'm attempting to write a library so that I can use it as a backend for a text editor that I am working on. The details of this project are irrelevant, but I would like to use sqlite as a file format. I'm running into issues when I am setting up migrations (I'm guessing I will run into further issues along the way), because I do not have a database created when the library is initially loaded. I started to look at the CLI source code to see if I could figure out what it was doing. Since that is a general purpose tool, there is a lot of code that I don't need for this project.

Is there a documented way to write a program that creates a database from scratch programatically?

@weiznich weiznich added the question label Apr 3, 2018

@weiznich

This comment has been minimized.

Contributor

weiznich commented Apr 3, 2018

Using the embed_migrations! macro from diesel_migrations it is possible to store the sql migrations inside your application binary. If the backend is sqlite and the database does not exist a call to embedded_migrations::run will create a new database file.

@jneumann

This comment has been minimized.

jneumann commented Apr 5, 2018

If I'm understanding the documentation correctly, establish_connection() returns a struct that implements diesel::prelude::Connection, correct?

@sgrif

This comment has been minimized.

Member

sgrif commented Apr 5, 2018

Yes. In your case that's probably a SqliteConnection

@jneumann

This comment has been minimized.

jneumann commented Apr 26, 2018

I kind of forgot I opened this issues. Thanks for the help, you guys rock!

@jneumann jneumann closed this Apr 26, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment