Compare commits
10 Commits
3f79435766
...
0881086e6a
Author | SHA1 | Date |
---|---|---|
Luke Murphy | 0881086e6a | |
Luke Murphy | 5a3be29467 | |
Luke Murphy | a54dd506ab | |
Luke Murphy | dcfb1fd4d2 | |
Luke Murphy | d152c9eb52 | |
Luke Murphy | 817efa77f6 | |
Luke Murphy | 68488ee2aa | |
Luke Murphy | 53c409502c | |
Luke Murphy | 7d1081b7e5 | |
Luke Murphy | d87ac9ddc9 |
|
@ -33,10 +33,11 @@ Calibrestekje is a Python library which provides a way to work with the
|
|||
`Calibre`_ database outside the context of the Calibre desktop and web
|
||||
interfaces.
|
||||
|
||||
Generated `SQLAlchemy`_ database bindings (see `sqlacodegen`_ for
|
||||
more) are provided which allow for read/write access to an existing Calibre
|
||||
Generated `SQLAlchemy`_ database bindings (see `sqlacodegen`_ for more)
|
||||
are provided which allow for read/write access to an existing Calibre
|
||||
database. These bindings are more fine grained than Calibres `database
|
||||
interface`_ and provide direct access to the Database table layer.
|
||||
interface`_ and provide direct access to the Database table layer. The
|
||||
bindings are generated from Calibre version ``2.75.1``.
|
||||
|
||||
A `flask`_ extension is also provided for getting started with web prototyping.
|
||||
Please see `flask-calibrestekje`_ and `the flask usage documentation`_ for
|
||||
|
|
|
@ -49,6 +49,13 @@ it is required to run this magical incantation that is hard to remember.
|
|||
Afterwards, you'll have a new ``mytestcalibredb/metadata.db`` empty database
|
||||
which you can start to work with.
|
||||
|
||||
If you want to run Calibre only using this new library, you can do the
|
||||
following. Otherwise, Calibre will default to the standard database location.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ calibre --with-library mytestcalibredb
|
||||
|
||||
Initialising a new session
|
||||
--------------------------
|
||||
|
||||
|
@ -65,7 +72,7 @@ All books without a publisher
|
|||
.. code-block:: python
|
||||
|
||||
(session.query(Book)
|
||||
.filter(Book.publishers == None))
|
||||
.filter(Book.publishers == None))
|
||||
|
||||
List of all tags that contain some pattern
|
||||
------------------------------------------
|
||||
|
@ -73,7 +80,7 @@ List of all tags that contain some pattern
|
|||
.. code-block:: python
|
||||
|
||||
(session.query(Tag)
|
||||
.filter(Tag.name.contains("humanities")))
|
||||
.filter(Tag.name.contains("humanities")))
|
||||
|
||||
Adding a new tag to a book
|
||||
--------------------------
|
||||
|
@ -96,6 +103,6 @@ All books with multiple authors
|
|||
from sqlalchemy.sql.expression import func
|
||||
|
||||
(session.query(Book)
|
||||
.join(Book.authors)
|
||||
.group_by(Book)
|
||||
.having(func.count(Author.id) > 1))
|
||||
.join(Book.authors)
|
||||
.group_by(Book)
|
||||
.having(func.count(Author.id) > 1))
|
||||
|
|
|
@ -1,26 +1,27 @@
|
|||
.. _flasking:
|
||||
|
||||
**************
|
||||
Use with Flask
|
||||
**************
|
||||
*******************
|
||||
Flask-Calibrestekje
|
||||
*******************
|
||||
|
||||
A `flask`_ extension is also provided so it's easy to get started with
|
||||
developing new web interfaces with calibrestekje. In order to get started
|
||||
you'll need to install the extension.
|
||||
A `flask`_ extension is available for prototyping new web interfaces with
|
||||
calibrestekje.
|
||||
|
||||
.. _flask: https://flask.palletsprojects.com
|
||||
|
||||
To get started you'll need to install the extension.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ pip install flask-calibrestekje
|
||||
|
||||
And then go ahead and create a ``flaskconfig.cfg`` file.
|
||||
Then create an ``app.cfg`` file with the following contents.
|
||||
|
||||
.. code-block:: cfg
|
||||
|
||||
CALIBRESTEKJE_SQLITE_URL = "sqlite:///mymetadata.db"
|
||||
|
||||
And then finally, create your Flask application.
|
||||
Create your Flask application in an ``app.py``.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
|
@ -30,9 +31,17 @@ And then finally, create your Flask application.
|
|||
from flask_calibrestekje import CalibreStekje
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.from_pyfile("config.cfg")
|
||||
app.config.from_pyfile("app.cfg")
|
||||
|
||||
db = CalibreStekje(app)
|
||||
|
||||
@app.route("/")
|
||||
def home():
|
||||
return jsonify({"book-count": db.session.query(Book).count()})
|
||||
|
||||
And finally, run your application.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ export FLASK_APP=app.py
|
||||
$ flask run
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
.. _forking:
|
||||
|
||||
*******
|
||||
Forking
|
||||
*******
|
||||
|
||||
If you'd like to go beyond Calibre and embark on a new experimental library but
|
||||
do not want to have to re-invent the database schema, you can get `SQLAlchemy`_
|
||||
ecosystem tooling to output SQLAlchemy schemas definition based on Calibre but
|
||||
ones which you can change yourself. This makes it possible to add new columns
|
||||
and tables to your new database.
|
||||
|
||||
.. _SQLALchemy: https://docs.sqlalchemy.org/
|
||||
|
||||
To get started, you would run the following commands.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ pip install sqlacodegen
|
||||
$ sqlacodegen --noviews "sqlite:///path_to_my_calibre_metadata.db" > mynewdb.py
|
||||
|
||||
If you look in ``mynewdb.py``, Sqlacodegen may have included a table called
|
||||
``t_sqlite_sequence``. You will want to remove this as I've only seen errors
|
||||
related to this table for some reasons which are not clear now.
|
||||
|
||||
Feel free to add, delete and change columns and tables in the ``mynewdb.py``
|
||||
file! It will be used to generate a brand new Sqlite database in which you have
|
||||
a free hand to design a model for whatever ideas you might want to work with in
|
||||
your new library software.
|
||||
|
||||
To generate the new Sqlite database, run the following.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from mynewdb import Base
|
||||
from sqlalchemy import create_engine
|
||||
|
||||
engine = create_engine('sqlite:///mynewdb.db')
|
||||
|
||||
Base.metadata.create_all(engine)
|
||||
|
||||
As a final check, it is then possible to investigate your new database with
|
||||
`sqlitebrowser`_ to check that the new database matches what you have defined
|
||||
in your ``mynewdb.py``.
|
||||
|
||||
.. _sqlitebrowser: https://sqlitebrowser.org/
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
sqlitebrowser mynewdb.db
|
|
@ -8,7 +8,6 @@
|
|||
install
|
||||
examples
|
||||
modules-api
|
||||
forking
|
||||
flask
|
||||
upgrade
|
||||
contribute
|
||||
|
|
Loading…
Reference in New Issue