I have been searching for libraries that can handle database migration for tornado framework. How is the database migration handled in Tornado framework ?
I was working on Yii Framework before and it has a very convenient CLI tool to handle Database migration.
I am looking for something like that.
I highly recommend Alembic. It was originally written to support SQLAlchemy, but you don't need to use SQLAlchemy as long you have a relational database it supports. That said, you will need to understand SQLAlchemy Core to work with Alembic, but that is generally a useful skill to have.
Related
Its's nice to see mongodb is connected with django but doesn't support completely. I explain why so because when you install any third party packages to your project it could written for Django models not Djongo which will fall you in Database error while migrating you apps.
djongo.database.DatabaseError
Do we have any solution for this case?
Well, in the general case, the solutions you have are, in increasing order of difficulty:
Get rid of Djongo. Use Django with an SQL database, as that's what it's designed for. You can still use MongoDB for whatever data you might have in there, but the main Django database is better off being SQL.
Don't use packages that don't work with Djongo.
Fix the packages that don't work with Djongo to work with it.
I would recommend going for (1)...
Is there any library or tool to perform database migrations in python without SQLAlchemy? I am using a PostgreSQL database and the queries are raw SQL. I use psycopg2 for the database connection.
In short, "yes."
There are numerous possibilities. The one you choose will depend on doing some homework to determine which one best suits your needs.
https://github.com/amacneil/dbmate
https://pypi.org/project/yoyo-migrations/
https://pypi.org/project/alembic/
Suggest when asking questions that can be answered with a google search, to be more specific about your situation, to help answerers to understand why Google couldn't answer your question in the first page of results.
If you can bring yourself to do your db migrations outside of the CLR, I'd strongly recommend considering FlyWay. It has been around forever, it's supported by RedGate, and the community version is free and open source. It has built-in support for all the major db platforms and installs like any other utility you'd use. For a Python app you'd do all of your db migrations via shell scripts or process calls instead of directly in the code.
My team settled on this tech because:
Yoyo is pretty immature and buggy for us
We don't use SQLAlchemy's OR framework
Alembic's syntax and framework seems pretty heavyweight for us
Under FlyWay's model we just write SQL scripts and check them into a directory. It's really lightweight.
It's been proven to work nicely in clustered environments
Give it a look.
I know that in Django I can fetch objects from the DB with something like ModelName.objects.filter().
Is there an analogous pattern in CherryPy?
Yes but not native. There are a couple of python ORM's that appear to work great with cherry pie with similar syntax to django. SQLAlchemy is an extremely popular very well supported ORM. It has a huge active community and is probably the de-facto python ORM. THere is a tool posted on cherrypy site that helps with integration.
From wikipedia:
Object-relational mappers:
SQLAlchemy — a database backend and ORM for Python applications. TurboGears 2.x uses CherryPy as server and SQLAlchemy as its default ORM.[13]
SQLObject — a popular ORM for providing an object interface to your database. Supports a number of common database backends: included in the distribution are MySQL, PostgreSQL, SQLite, Sybase SQL Server, MaxDB, Microsoft SQL Server and Firebird. TurboGears 1.x uses CherryPy as server and SQLObject as ORM.[14]
Storm — the ORM from Canonical Ltd. (makers of Ubuntu)
Dejavu[15] — a public domain, thread-safe ORM for Python applications
i am new in python.before this i done some work in php with codeigniter framework.
now i want to develop website using python and sqlite3.
so which framework will you suggest me.
i also want to know IDE for sqlite.
Do you mean something similar to sqliteman or dbeaver? These are not not IDEs for SQLite, but instead, are GUI interfaces. There are more here: http://www.google.com/search?&q=sqlite+gui
3rd link down is another stack overflow question: What are good open source GUI SQLite database managers?
For Python web frameworks, a very popular full-stack framework is the Django Project
Check out web2py. It's a feature-rich full-stack framework, but it's also very easy to set up, learn, and use. It requires no installation or configuration, has no dependencies, and includes its own web server and web-based IDE/administrative interface (see demo). If you download the binary version for Windows or Mac, it even includes its own Python interpreter (so you don't need to have Python installed).
The database abstraction layer (DAL) works with 10 different database backends, including SQLite. It doesn't include its own SQLite IDE, though it does include a database administrative interface called appadmin, which allows you to view all database tables; view, insert, update, and delete records within each table; and import/export tables to CSV. You can also import and export the entire database to CSV. (Note, these features work for all database backends, not just SQLite.)
You will probably also find that you don't really need an IDE for SQLite when using web2py because the DAL takes care of everything for you. You specify all of your data models using the DAL syntax, and then the DAL automatically creates the SQLite database, creates all tables, and handles migrations when you changes your models.
If you have any questions, there's a friendly and responsive mailing list that will provide lots of help.
I love the abstract database API that comes with Django, I was wondering if I could use this (or something similar) to model, access, and manage my (postgres) database for my non-Django Python projects.
What you're looking for is an object-relational mapper (ORM). Django has its own, built-in.
To use Django's ORM by itself:
Using the Django ORM as a standalone component
Use Django ORM as standalone
Using settings without setting DJANGO_SETTINGS_MODULE
If you want to use something else:
What are some good Python ORM solutions?
Popular stand-alone ORMs for Python:
SQLAlchemy
SQLObject
Storm
They all support MySQL and PostgreSQL (among others).
I especially like SQLAlchemy with following tools:
Elixir (declarative syntax)
Migrate (schema migration)
They really remind me of ActiveRecord.