![]() MYSQL_TEST_DB_CONNECTION - defaults to POSTGRESQL_TEST_DB_CONNECTION - defaults to postgresql://localhost/test_db_to_sqlite.You can use environment variables to point them at different test database servers: The PostgreSQL and MySQL tests default to expecting to run against servers on localhost. See Running a MySQL server using Homebrew for tips on running the tests against MySQL on macOS, including how to install the mysqlclient dependency. You can alternative use pip install psycopg2-binary if you cannot install the psycopg2 dependency used by the test_postgresql extra. You can install those extra dependencies like so: pip install -e '.' This will skip tests against MySQL or PostgreSQL if you do not have their additional dependencies installed. Now install the dependencies and test dependencies: pip install -e '.' Then create a new virtual environment: cd db-to-sqlite To set up this tool locally, first checkout the code. csvs-to-sqlite: Convert CSV files into a SQLite database.sqlite-utils: Python CLI utility and library for manipulating SQLite databases.Works great with SQLite files generated using db-to-sqlite. Datasette: A tool for exploring and publishing data.You can even do this using a bash one-liner: $ db-to-sqlite $(heroku config -app myappname | grep HEROKU_POSTG | cut -d: -f 2-) \ HEROKU_POSTGRESQL_OLIVE_URL: can pass this to db-to-sqlite to create a local SQLite database with the data from your Heroku instance. If you run an application on Heroku using their Postgres database product, you can use the heroku config command to access a compatible connection string: $ heroku config -app myappname | grep HEROKU_POSTG Mssql+pyodbc:///?odbc_connect=DRIVER%3D%7BSQL+Server+Native+Client+11.0%7D%3B+SERVER%3Dlocalhost%3B+DATABASE%3Dmy_database%3B+UID%3Dusername%3B+PWD%3Dpasswd You can then use the string above in the odbc_connect below mssql+pyodbc:///?odbc_connect=DRIVER%3D%7BSQL+Server+Native+Client+11.0%7D%3B+SERVER%3Dlocalhost%3B+DATABASE%3Dmy_database%3B+Trusted_Connection%3Dyes The above will resolve to DRIVER%3D%7BSQL+Server+Native+Client+11.0%7D%3B+SERVER%3Dlocalhost%3B+DATABASE%3Dmy_database%3B+Trusted_Connection%3Dyes The best way to get the connection string needed for the MS SQL connections below is to use urllib from the Standard Library as below params = _plus( If the tables you want to copy from your PostgreSQL database aren't in the default schema, you can specify an alternate one with the -postgres-schema option: db-to-sqlite "postgresql://localhost/myblog" blog.db \ Using db-to-sqlite with PostgreSQL schemas The -output option specifies the table that should contain the results of the query. sql="select id, title, created from blog_entry" \ If you want to save the results of a custom SQL query, do this: db-to-sqlite "postgresql://localhost/myblog" output.db \ When running -all you can specify tables to skip using -skip: db-to-sqlite "postgresql://localhost/myblog" blog.db \ For example: db-to-sqlite "postgresql://localhost/myblog" blog.db \ Any foreign key relationships will be detected and added to the SQLite database. You can also save the data from all of your tables, effectively creating a SQLite copy of your entire database. postgres-schema TEXT PostgreSQL schema to useįor example, to save the content of the blog_entry table from a PostgreSQL database to a local file called blog.db you could do this: db-to-sqlite "postgresql://localhost/myblog" blog.db \ index-fks / -no-index-fks Should foreign keys have indexes? Default on pk TEXT Optional column to use as a primary key output TEXT Table in which to save -sql query results skip TEXT When using -all skip these tables tmp/my_database.dbĬONNECTION is a SQLAlchemy connection string, for PATH is a path to the SQLite file to create, e.c. Usage Usage: db-to-sqlite CONNECTION PATH Installing the mysqlclient library on OS X can be tricky - I've found this recipe to work (run that before installing db-to-sqlite).įor PostgreSQL, use this: pip install 'db-to-sqlite' If you want to use it with MySQL, you can install the extra dependency like this: pip install 'db-to-sqlite' Install from PyPI like so: pip install db-to-sqlite CLI tool for exporting tables or queries from any SQL database to a SQLite file.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |