Adding sphinx documentation
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -16,6 +16,9 @@ develop-eggs
|
||||
# Installer logs
|
||||
pip-log.txt
|
||||
|
||||
# Docs
|
||||
html/
|
||||
|
||||
# IDE
|
||||
.project
|
||||
.pydevproject
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
CHANGELOG
|
||||
|
||||
0.0.4-ALPHA (in progress)
|
||||
* added Sphinx docs
|
||||
* changing create_column_family management function to create_table
|
||||
* changing delete_column_family management function to delete_table
|
||||
* added partition key validation to QuerySet delete method
|
||||
|
||||
153
docs/Makefile
Normal file
153
docs/Makefile
Normal file
@@ -0,0 +1,153 @@
|
||||
# Makefile for Sphinx documentation
|
||||
#
|
||||
|
||||
# You can set these variables from the command line.
|
||||
SPHINXOPTS =
|
||||
SPHINXBUILD = sphinx-build
|
||||
PAPER =
|
||||
BUILDDIR = _build
|
||||
|
||||
# Internal variables.
|
||||
PAPEROPT_a4 = -D latex_paper_size=a4
|
||||
PAPEROPT_letter = -D latex_paper_size=letter
|
||||
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
|
||||
# the i18n builder cannot share the environment and doctrees with the others
|
||||
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
|
||||
|
||||
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext
|
||||
|
||||
help:
|
||||
@echo "Please use \`make <target>' where <target> is one of"
|
||||
@echo " html to make standalone HTML files"
|
||||
@echo " dirhtml to make HTML files named index.html in directories"
|
||||
@echo " singlehtml to make a single large HTML file"
|
||||
@echo " pickle to make pickle files"
|
||||
@echo " json to make JSON files"
|
||||
@echo " htmlhelp to make HTML files and a HTML help project"
|
||||
@echo " qthelp to make HTML files and a qthelp project"
|
||||
@echo " devhelp to make HTML files and a Devhelp project"
|
||||
@echo " epub to make an epub"
|
||||
@echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
|
||||
@echo " latexpdf to make LaTeX files and run them through pdflatex"
|
||||
@echo " text to make text files"
|
||||
@echo " man to make manual pages"
|
||||
@echo " texinfo to make Texinfo files"
|
||||
@echo " info to make Texinfo files and run them through makeinfo"
|
||||
@echo " gettext to make PO message catalogs"
|
||||
@echo " changes to make an overview of all changed/added/deprecated items"
|
||||
@echo " linkcheck to check all external links for integrity"
|
||||
@echo " doctest to run all doctests embedded in the documentation (if enabled)"
|
||||
|
||||
clean:
|
||||
-rm -rf $(BUILDDIR)/*
|
||||
|
||||
html:
|
||||
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
|
||||
|
||||
dirhtml:
|
||||
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
|
||||
@echo
|
||||
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
|
||||
|
||||
singlehtml:
|
||||
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
|
||||
@echo
|
||||
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
|
||||
|
||||
pickle:
|
||||
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
|
||||
@echo
|
||||
@echo "Build finished; now you can process the pickle files."
|
||||
|
||||
json:
|
||||
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
|
||||
@echo
|
||||
@echo "Build finished; now you can process the JSON files."
|
||||
|
||||
htmlhelp:
|
||||
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
|
||||
@echo
|
||||
@echo "Build finished; now you can run HTML Help Workshop with the" \
|
||||
".hhp project file in $(BUILDDIR)/htmlhelp."
|
||||
|
||||
qthelp:
|
||||
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
|
||||
@echo
|
||||
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
|
||||
".qhcp project file in $(BUILDDIR)/qthelp, like this:"
|
||||
@echo "# qcollectiongenerator $(BUILDDIR)/qthelp/cqlengine.qhcp"
|
||||
@echo "To view the help file:"
|
||||
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/cqlengine.qhc"
|
||||
|
||||
devhelp:
|
||||
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
|
||||
@echo
|
||||
@echo "Build finished."
|
||||
@echo "To view the help file:"
|
||||
@echo "# mkdir -p $$HOME/.local/share/devhelp/cqlengine"
|
||||
@echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/cqlengine"
|
||||
@echo "# devhelp"
|
||||
|
||||
epub:
|
||||
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
|
||||
@echo
|
||||
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."
|
||||
|
||||
latex:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo
|
||||
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
|
||||
@echo "Run \`make' in that directory to run these through (pdf)latex" \
|
||||
"(use \`make latexpdf' here to do that automatically)."
|
||||
|
||||
latexpdf:
|
||||
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
|
||||
@echo "Running LaTeX files through pdflatex..."
|
||||
$(MAKE) -C $(BUILDDIR)/latex all-pdf
|
||||
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
|
||||
|
||||
text:
|
||||
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
|
||||
@echo
|
||||
@echo "Build finished. The text files are in $(BUILDDIR)/text."
|
||||
|
||||
man:
|
||||
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
|
||||
@echo
|
||||
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."
|
||||
|
||||
texinfo:
|
||||
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
|
||||
@echo
|
||||
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
|
||||
@echo "Run \`make' in that directory to run these through makeinfo" \
|
||||
"(use \`make info' here to do that automatically)."
|
||||
|
||||
info:
|
||||
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
|
||||
@echo "Running Texinfo files through makeinfo..."
|
||||
make -C $(BUILDDIR)/texinfo info
|
||||
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
|
||||
|
||||
gettext:
|
||||
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
|
||||
@echo
|
||||
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
|
||||
|
||||
changes:
|
||||
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
|
||||
@echo
|
||||
@echo "The overview file is in $(BUILDDIR)/changes."
|
||||
|
||||
linkcheck:
|
||||
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
|
||||
@echo
|
||||
@echo "Link check complete; look for any errors in the above output " \
|
||||
"or in $(BUILDDIR)/linkcheck/output.txt."
|
||||
|
||||
doctest:
|
||||
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
|
||||
@echo "Testing of doctests in the sources finished, look at the " \
|
||||
"results in $(BUILDDIR)/doctest/output.txt."
|
||||
242
docs/conf.py
Normal file
242
docs/conf.py
Normal file
@@ -0,0 +1,242 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# cqlengine documentation build configuration file, created by
|
||||
# sphinx-quickstart on Sat Dec 1 09:50:49 2012.
|
||||
#
|
||||
# This file is execfile()d with the current directory set to its containing dir.
|
||||
#
|
||||
# Note that not all possible configuration values are present in this
|
||||
# autogenerated file.
|
||||
#
|
||||
# All configuration values have a default; values that are commented out
|
||||
# serve to show the default.
|
||||
|
||||
import sys, os
|
||||
|
||||
# If extensions (or modules to document with autodoc) are in another directory,
|
||||
# add these directories to sys.path here. If the directory is relative to the
|
||||
# documentation root, use os.path.abspath to make it absolute, like shown here.
|
||||
#sys.path.insert(0, os.path.abspath('.'))
|
||||
|
||||
# -- General configuration -----------------------------------------------------
|
||||
|
||||
# If your documentation needs a minimal Sphinx version, state it here.
|
||||
#needs_sphinx = '1.0'
|
||||
|
||||
# Add any Sphinx extension module names here, as strings. They can be extensions
|
||||
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
|
||||
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.coverage', 'sphinx.ext.pngmath', 'sphinx.ext.mathjax']
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ['_templates']
|
||||
|
||||
# The suffix of source filenames.
|
||||
source_suffix = '.rst'
|
||||
|
||||
# The encoding of source files.
|
||||
#source_encoding = 'utf-8-sig'
|
||||
|
||||
# The master toctree document.
|
||||
master_doc = 'index'
|
||||
|
||||
# General information about the project.
|
||||
project = u'cqlengine'
|
||||
copyright = u'2012, Blake Eggleston'
|
||||
|
||||
# The version info for the project you're documenting, acts as replacement for
|
||||
# |version| and |release|, also used in various other places throughout the
|
||||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = '0.0.3'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = '0.0.3'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
#language = None
|
||||
|
||||
# There are two options for replacing |today|: either, you set today to some
|
||||
# non-false value, then it is used:
|
||||
#today = ''
|
||||
# Else, today_fmt is used as the format for a strftime call.
|
||||
#today_fmt = '%B %d, %Y'
|
||||
|
||||
# List of patterns, relative to source directory, that match files and
|
||||
# directories to ignore when looking for source files.
|
||||
exclude_patterns = ['_build']
|
||||
|
||||
# The reST default role (used for this markup: `text`) to use for all documents.
|
||||
#default_role = None
|
||||
|
||||
# If true, '()' will be appended to :func: etc. cross-reference text.
|
||||
#add_function_parentheses = True
|
||||
|
||||
# If true, the current module name will be prepended to all description
|
||||
# unit titles (such as .. function::).
|
||||
#add_module_names = True
|
||||
|
||||
# If true, sectionauthor and moduleauthor directives will be shown in the
|
||||
# output. They are ignored by default.
|
||||
#show_authors = False
|
||||
|
||||
# The name of the Pygments (syntax highlighting) style to use.
|
||||
pygments_style = 'sphinx'
|
||||
|
||||
# A list of ignored prefixes for module index sorting.
|
||||
#modindex_common_prefix = []
|
||||
|
||||
|
||||
# -- Options for HTML output ---------------------------------------------------
|
||||
|
||||
# The theme to use for HTML and HTML Help pages. See the documentation for
|
||||
# a list of builtin themes.
|
||||
html_theme = 'default'
|
||||
|
||||
# Theme options are theme-specific and customize the look and feel of a theme
|
||||
# further. For a list of options available for each theme, see the
|
||||
# documentation.
|
||||
#html_theme_options = {}
|
||||
|
||||
# Add any paths that contain custom themes here, relative to this directory.
|
||||
#html_theme_path = []
|
||||
|
||||
# The name for this set of Sphinx documents. If None, it defaults to
|
||||
# "<project> v<release> documentation".
|
||||
#html_title = None
|
||||
|
||||
# A shorter title for the navigation bar. Default is the same as html_title.
|
||||
#html_short_title = None
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top
|
||||
# of the sidebar.
|
||||
#html_logo = None
|
||||
|
||||
# The name of an image file (within the static path) to use as favicon of the
|
||||
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
|
||||
# pixels large.
|
||||
#html_favicon = None
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
html_static_path = ['_static']
|
||||
|
||||
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
|
||||
# using the given strftime format.
|
||||
#html_last_updated_fmt = '%b %d, %Y'
|
||||
|
||||
# If true, SmartyPants will be used to convert quotes and dashes to
|
||||
# typographically correct entities.
|
||||
#html_use_smartypants = True
|
||||
|
||||
# Custom sidebar templates, maps document names to template names.
|
||||
#html_sidebars = {}
|
||||
|
||||
# Additional templates that should be rendered to pages, maps page names to
|
||||
# template names.
|
||||
#html_additional_pages = {}
|
||||
|
||||
# If false, no module index is generated.
|
||||
#html_domain_indices = True
|
||||
|
||||
# If false, no index is generated.
|
||||
#html_use_index = True
|
||||
|
||||
# If true, the index is split into individual pages for each letter.
|
||||
#html_split_index = False
|
||||
|
||||
# If true, links to the reST sources are added to the pages.
|
||||
#html_show_sourcelink = True
|
||||
|
||||
# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
|
||||
#html_show_sphinx = True
|
||||
|
||||
# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
|
||||
#html_show_copyright = True
|
||||
|
||||
# If true, an OpenSearch description file will be output, and all pages will
|
||||
# contain a <link> tag referring to it. The value of this option must be the
|
||||
# base URL from which the finished HTML is served.
|
||||
#html_use_opensearch = ''
|
||||
|
||||
# This is the file name suffix for HTML files (e.g. ".xhtml").
|
||||
#html_file_suffix = None
|
||||
|
||||
# Output file base name for HTML help builder.
|
||||
htmlhelp_basename = 'cqlenginedoc'
|
||||
|
||||
|
||||
# -- Options for LaTeX output --------------------------------------------------
|
||||
|
||||
latex_elements = {
|
||||
# The paper size ('letterpaper' or 'a4paper').
|
||||
#'papersize': 'letterpaper',
|
||||
|
||||
# The font size ('10pt', '11pt' or '12pt').
|
||||
#'pointsize': '10pt',
|
||||
|
||||
# Additional stuff for the LaTeX preamble.
|
||||
#'preamble': '',
|
||||
}
|
||||
|
||||
# Grouping the document tree into LaTeX files. List of tuples
|
||||
# (source start file, target name, title, author, documentclass [howto/manual]).
|
||||
latex_documents = [
|
||||
('index', 'cqlengine.tex', u'cqlengine Documentation',
|
||||
u'Blake Eggleston', 'manual'),
|
||||
]
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top of
|
||||
# the title page.
|
||||
#latex_logo = None
|
||||
|
||||
# For "manual" documents, if this is true, then toplevel headings are parts,
|
||||
# not chapters.
|
||||
#latex_use_parts = False
|
||||
|
||||
# If true, show page references after internal links.
|
||||
#latex_show_pagerefs = False
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
#latex_show_urls = False
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
#latex_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
#latex_domain_indices = True
|
||||
|
||||
|
||||
# -- Options for manual page output --------------------------------------------
|
||||
|
||||
# One entry per manual page. List of tuples
|
||||
# (source start file, name, description, authors, manual section).
|
||||
man_pages = [
|
||||
('index', 'cqlengine', u'cqlengine Documentation',
|
||||
[u'Blake Eggleston'], 1)
|
||||
]
|
||||
|
||||
# If true, show URL addresses after external links.
|
||||
#man_show_urls = False
|
||||
|
||||
|
||||
# -- Options for Texinfo output ------------------------------------------------
|
||||
|
||||
# Grouping the document tree into Texinfo files. List of tuples
|
||||
# (source start file, target name, title, author,
|
||||
# dir menu entry, description, category)
|
||||
texinfo_documents = [
|
||||
('index', 'cqlengine', u'cqlengine Documentation',
|
||||
u'Blake Eggleston', 'cqlengine', 'One line description of project.',
|
||||
'Miscellaneous'),
|
||||
]
|
||||
|
||||
# Documents to append as an appendix to all manuals.
|
||||
#texinfo_appendices = []
|
||||
|
||||
# If false, no module index is generated.
|
||||
#texinfo_domain_indices = True
|
||||
|
||||
# How to display URL addresses: 'footnote', 'no', or 'inline'.
|
||||
#texinfo_show_urls = 'footnote'
|
||||
100
docs/index.rst
Normal file
100
docs/index.rst
Normal file
@@ -0,0 +1,100 @@
|
||||
|
||||
.. _index:
|
||||
|
||||
=======================
|
||||
cqlengine documentation
|
||||
=======================
|
||||
|
||||
cqlengine is a Cassandra CQL ORM for Python with an interface similar to the Django orm and mongoengine
|
||||
|
||||
:ref:`getting-started`
|
||||
|
||||
Contents:
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
|
||||
topics/models
|
||||
topics/queryset
|
||||
topics/columns
|
||||
topics/connection
|
||||
topics/manage_schemas
|
||||
|
||||
.. _getting-started:
|
||||
|
||||
Getting Started
|
||||
===============
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
#first, define a model
|
||||
>>> from cqlengine import columns
|
||||
>>> from cqlengine import Model
|
||||
|
||||
>>> class ExampleModel(Model):
|
||||
>>> example_id = columns.UUID(primary_key=True)
|
||||
>>> example_type = columns.Integer(index=True)
|
||||
>>> created_at = columns.DateTime()
|
||||
>>> description = columns.Text(required=False)
|
||||
|
||||
#next, setup the connection to your cassandra server(s)...
|
||||
>>> from cqlengine import connection
|
||||
>>> connection.setup(['127.0.0.1:9160'])
|
||||
|
||||
#...and create your CQL table
|
||||
>>> from cqlengine.management import create_table
|
||||
>>> create_table(ExampleModel)
|
||||
|
||||
#now we can create some rows:
|
||||
>>> em1 = ExampleModel.create(example_type=0, description="example1")
|
||||
>>> em2 = ExampleModel.create(example_type=0, description="example2")
|
||||
>>> em3 = ExampleModel.create(example_type=0, description="example3")
|
||||
>>> em4 = ExampleModel.create(example_type=0, description="example4")
|
||||
>>> em5 = ExampleModel.create(example_type=1, description="example5")
|
||||
>>> em6 = ExampleModel.create(example_type=1, description="example6")
|
||||
>>> em7 = ExampleModel.create(example_type=1, description="example7")
|
||||
>>> em8 = ExampleModel.create(example_type=1, description="example8")
|
||||
# Note: the UUID and DateTime columns will create uuid4 and datetime.now
|
||||
# values automatically if we don't specify them when creating new rows
|
||||
|
||||
#and now we can run some queries against our table
|
||||
>>> ExampleModel.objects.count()
|
||||
8
|
||||
>>> q = ExampleModel.objects(example_type=1)
|
||||
>>> q.count()
|
||||
4
|
||||
>>> for instance in q:
|
||||
>>> print q.description
|
||||
example5
|
||||
example6
|
||||
example7
|
||||
example8
|
||||
|
||||
#here we are applying additional filtering to an existing query
|
||||
#query objects are immutable, so calling filter returns a new
|
||||
#query object
|
||||
>>> q2 = q.filter(example_id=em5.example_id)
|
||||
|
||||
>>> q2.count()
|
||||
1
|
||||
>>> for instance in q2:
|
||||
>>> print q.description
|
||||
example5
|
||||
|
||||
|
||||
`Report a Bug <https://github.com/bdeggleston/cqlengine/issues>`_
|
||||
|
||||
`Users Mailing List <https://groups.google.com/forum/?fromgroups#!forum/cqlengine-users>`_
|
||||
|
||||
`Dev Mailing List <https://groups.google.com/forum/?fromgroups#!forum/cqlengine-dev>`_
|
||||
|
||||
**NOTE: cqlengine is in alpha and under development, some features may change. Make sure to check the changelog and test your app before upgrading**
|
||||
|
||||
|
||||
Indices and tables
|
||||
==================
|
||||
|
||||
* :ref:`genindex`
|
||||
* :ref:`modindex`
|
||||
* :ref:`search`
|
||||
|
||||
190
docs/make.bat
Normal file
190
docs/make.bat
Normal file
@@ -0,0 +1,190 @@
|
||||
@ECHO OFF
|
||||
|
||||
REM Command file for Sphinx documentation
|
||||
|
||||
if "%SPHINXBUILD%" == "" (
|
||||
set SPHINXBUILD=sphinx-build
|
||||
)
|
||||
set BUILDDIR=_build
|
||||
set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% .
|
||||
set I18NSPHINXOPTS=%SPHINXOPTS% .
|
||||
if NOT "%PAPER%" == "" (
|
||||
set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
|
||||
set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
|
||||
)
|
||||
|
||||
if "%1" == "" goto help
|
||||
|
||||
if "%1" == "help" (
|
||||
:help
|
||||
echo.Please use `make ^<target^>` where ^<target^> is one of
|
||||
echo. html to make standalone HTML files
|
||||
echo. dirhtml to make HTML files named index.html in directories
|
||||
echo. singlehtml to make a single large HTML file
|
||||
echo. pickle to make pickle files
|
||||
echo. json to make JSON files
|
||||
echo. htmlhelp to make HTML files and a HTML help project
|
||||
echo. qthelp to make HTML files and a qthelp project
|
||||
echo. devhelp to make HTML files and a Devhelp project
|
||||
echo. epub to make an epub
|
||||
echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
|
||||
echo. text to make text files
|
||||
echo. man to make manual pages
|
||||
echo. texinfo to make Texinfo files
|
||||
echo. gettext to make PO message catalogs
|
||||
echo. changes to make an overview over all changed/added/deprecated items
|
||||
echo. linkcheck to check all external links for integrity
|
||||
echo. doctest to run all doctests embedded in the documentation if enabled
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "clean" (
|
||||
for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
|
||||
del /q /s %BUILDDIR%\*
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "html" (
|
||||
%SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The HTML pages are in %BUILDDIR%/html.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "dirhtml" (
|
||||
%SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "singlehtml" (
|
||||
%SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "pickle" (
|
||||
%SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; now you can process the pickle files.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "json" (
|
||||
%SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; now you can process the JSON files.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "htmlhelp" (
|
||||
%SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; now you can run HTML Help Workshop with the ^
|
||||
.hhp project file in %BUILDDIR%/htmlhelp.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "qthelp" (
|
||||
%SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; now you can run "qcollectiongenerator" with the ^
|
||||
.qhcp project file in %BUILDDIR%/qthelp, like this:
|
||||
echo.^> qcollectiongenerator %BUILDDIR%\qthelp\cqlengine.qhcp
|
||||
echo.To view the help file:
|
||||
echo.^> assistant -collectionFile %BUILDDIR%\qthelp\cqlengine.ghc
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "devhelp" (
|
||||
%SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "epub" (
|
||||
%SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The epub file is in %BUILDDIR%/epub.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "latex" (
|
||||
%SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "text" (
|
||||
%SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The text files are in %BUILDDIR%/text.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "man" (
|
||||
%SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The manual pages are in %BUILDDIR%/man.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "texinfo" (
|
||||
%SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "gettext" (
|
||||
%SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "changes" (
|
||||
%SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.The overview file is in %BUILDDIR%/changes.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "linkcheck" (
|
||||
%SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Link check complete; look for any errors in the above output ^
|
||||
or in %BUILDDIR%/linkcheck/output.txt.
|
||||
goto end
|
||||
)
|
||||
|
||||
if "%1" == "doctest" (
|
||||
%SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
|
||||
if errorlevel 1 exit /b 1
|
||||
echo.
|
||||
echo.Testing of doctests in the sources finished, look at the ^
|
||||
results in %BUILDDIR%/doctest/output.txt.
|
||||
goto end
|
||||
)
|
||||
|
||||
:end
|
||||
100
docs/topics/columns.rst
Normal file
100
docs/topics/columns.rst
Normal file
@@ -0,0 +1,100 @@
|
||||
=======
|
||||
Columns
|
||||
=======
|
||||
|
||||
.. module:: cqlengine.columns
|
||||
|
||||
.. class:: Bytes()
|
||||
|
||||
Stores arbitrary bytes (no validation), expressed as hexadecimal ::
|
||||
|
||||
columns.Bytes()
|
||||
|
||||
|
||||
.. class:: Ascii()
|
||||
|
||||
Stores a US-ASCII character string ::
|
||||
|
||||
columns.Ascii()
|
||||
|
||||
|
||||
.. class:: Text()
|
||||
|
||||
Stores a UTF-8 encoded string ::
|
||||
|
||||
columns.Text()
|
||||
|
||||
.. class:: Integer()
|
||||
|
||||
Stores an integer value ::
|
||||
|
||||
columns.Integer()
|
||||
|
||||
.. class:: DateTime()
|
||||
|
||||
Stores a datetime value.
|
||||
|
||||
Python's datetime.now callable is set as the default value for this column ::
|
||||
|
||||
columns.DateTime()
|
||||
|
||||
.. class:: UUID()
|
||||
|
||||
Stores a type 1 or type 4 UUID.
|
||||
|
||||
Python's uuid.uuid4 callable is set as the default value for this column. ::
|
||||
|
||||
columns.UUID()
|
||||
|
||||
.. class:: Boolean()
|
||||
|
||||
Stores a boolean True or False value ::
|
||||
|
||||
columns.Boolean()
|
||||
|
||||
.. class:: Float()
|
||||
|
||||
Stores a floating point value ::
|
||||
|
||||
columns.Float()
|
||||
|
||||
**options**
|
||||
|
||||
:attr:`~columns.Float.double_precision`
|
||||
If True, stores a double precision float value, otherwise single precision. Defaults to True.
|
||||
|
||||
.. class:: Decimal()
|
||||
|
||||
Stores a variable precision decimal value ::
|
||||
|
||||
columns.Decimal()
|
||||
|
||||
Column Options
|
||||
==============
|
||||
|
||||
Each column can be defined with optional arguments to modify the way they behave. While some column types may define additional column options, these are the options that are available on all columns:
|
||||
|
||||
.. attribute:: BaseColumn.primary_key
|
||||
|
||||
If True, this column is created as a primary key field. A model can have multiple primary keys. Defaults to False.
|
||||
|
||||
*In CQL, there are 2 types of primary keys: partition keys and clustering keys. As with CQL, the first primary key is the partition key, and all others are clustering keys.*
|
||||
|
||||
.. attribute:: BaseColumn.index
|
||||
|
||||
If True, an index will be created for this column. Defaults to False.
|
||||
|
||||
*Note: Indexes can only be created on models with one primary key*
|
||||
|
||||
.. attribute:: BaseColumn.db_field
|
||||
|
||||
Explicitly sets the name of the column in the database table. If this is left blank, the column name will be the same as the name of the column attribute. Defaults to None.
|
||||
|
||||
.. attribute:: BaseColumn.default
|
||||
|
||||
The default value for this column. If a model instance is saved without a value for this column having been defined, the default value will be used. This can be either a value or a callable object (ie: datetime.now is a valid default argument).
|
||||
|
||||
.. attribute:: BaseColumn.required
|
||||
|
||||
If True, this model cannot be saved without a value defined for this column. Defaults to True. Primary key fields cannot have their required fields set to False.
|
||||
|
||||
19
docs/topics/connection.rst
Normal file
19
docs/topics/connection.rst
Normal file
@@ -0,0 +1,19 @@
|
||||
==============
|
||||
Connection
|
||||
==============
|
||||
|
||||
.. module:: cqlengine.connection
|
||||
|
||||
The setup function in `cqlengine.connection` records the Cassandra servers to connect to.
|
||||
If there is a problem with one of the servers, cqlengine will try to connect to each of the other connections before failing.
|
||||
|
||||
.. function:: setup(hosts [, username=None, password=None])
|
||||
|
||||
:param hosts: list of hosts, strings in the <hostname>:<port>, or just <hostname>
|
||||
:type hosts: list
|
||||
|
||||
Records the hosts and connects to one of them
|
||||
|
||||
See the example at :ref:`getting-started`
|
||||
|
||||
|
||||
43
docs/topics/manage_schemas.rst
Normal file
43
docs/topics/manage_schemas.rst
Normal file
@@ -0,0 +1,43 @@
|
||||
===============
|
||||
Managing Schmas
|
||||
===============
|
||||
|
||||
.. module:: cqlengine.management
|
||||
|
||||
Once a connection has been made to Cassandra, you can use the functions in ``cqlengine.management`` to create and delete keyspaces, as well as create and delete tables for defined models
|
||||
|
||||
.. function:: create_keyspace(name)
|
||||
|
||||
:param name: the keyspace name to create
|
||||
:type name: string
|
||||
|
||||
creates a keyspace with the given name
|
||||
|
||||
.. function:: delete_keyspace(name)
|
||||
|
||||
:param name: the keyspace name to delete
|
||||
:type name: string
|
||||
|
||||
deletes the keyspace with the given name
|
||||
|
||||
.. function:: create_table(model [, create_missing_keyspace=True])
|
||||
|
||||
:param model: the :class:`~cqlengine.model.Model` class to make a table with
|
||||
:type model: :class:`~cqlengine.model.Model`
|
||||
:param create_missing_keyspace: *Optional* If True, the model's keyspace will be created if it does not already exist. Defaults to ``True``
|
||||
:type create_missing_keyspace: bool
|
||||
|
||||
creates a CQL table for the given model
|
||||
|
||||
.. function:: delete_table(model)
|
||||
|
||||
:param model: the :class:`~cqlengine.model.Model` class to delete a column family for
|
||||
:type model: :class:`~cqlengine.model.Model`
|
||||
|
||||
deletes the CQL table for the given model
|
||||
|
||||
|
||||
|
||||
See the example at :ref:`getting-started`
|
||||
|
||||
|
||||
136
docs/topics/models.rst
Normal file
136
docs/topics/models.rst
Normal file
@@ -0,0 +1,136 @@
|
||||
======
|
||||
Models
|
||||
======
|
||||
|
||||
.. module:: cqlengine.models
|
||||
|
||||
A model is a python class representing a CQL table.
|
||||
|
||||
Example
|
||||
=======
|
||||
|
||||
This example defines a Person table, with the columns ``first_name`` and ``last_name``
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from cqlengine import columns
|
||||
from cqlengine.models import Model
|
||||
|
||||
class Person(Model):
|
||||
first_name = columns.Text()
|
||||
last_name = columns.Text()
|
||||
|
||||
|
||||
The Person model would create this CQL table:
|
||||
|
||||
.. code-block:: sql
|
||||
|
||||
CREATE TABLE cqlengine.person (
|
||||
id uuid,
|
||||
first_name text,
|
||||
last_name text,
|
||||
PRIMARY KEY (id)
|
||||
)
|
||||
|
||||
Columns
|
||||
=======
|
||||
|
||||
Columns in your models map to columns in your CQL table. You define CQL columns by defining column attributes on your model classes. For a model to be valid it needs at least one primary key column (defined automatically if you don't define one) and one non-primary key column.
|
||||
|
||||
Just as in CQL, the order you define your columns in is important, and is the same order they are defined in on a model's corresponding table.
|
||||
|
||||
Column Types
|
||||
============
|
||||
|
||||
Each column on your model definitions needs to an instance of a Column class. The column types that are included with cqlengine as of this writing are:
|
||||
|
||||
* :class:`~cqlengine.columns.Bytes`
|
||||
* :class:`~cqlengine.columns.Ascii`
|
||||
* :class:`~cqlengine.columns.Text`
|
||||
* :class:`~cqlengine.columns.Integer`
|
||||
* :class:`~cqlengine.columns.DateTime`
|
||||
* :class:`~cqlengine.columns.UUID`
|
||||
* :class:`~cqlengine.columns.Boolean`
|
||||
* :class:`~cqlengine.columns.Float`
|
||||
* :class:`~cqlengine.columns.Decimal`
|
||||
|
||||
A time uuid field is in the works.
|
||||
|
||||
Column Options
|
||||
--------------
|
||||
|
||||
Each column can be defined with optional arguments to modify the way they behave. While some column types may define additional column options, these are the options that are available on all columns:
|
||||
|
||||
:attr:`~cqlengine.columns.BaseColumn.primary_key`
|
||||
If True, this column is created as a primary key field. A model can have multiple primary keys. Defaults to False.
|
||||
|
||||
*In CQL, there are 2 types of primary keys: partition keys and clustering keys. As with CQL, the first primary key is the partition key, and all others are clustering keys.*
|
||||
|
||||
:attr:`~cqlengine.columns.BaseColumn.index`
|
||||
If True, an index will be created for this column. Defaults to False.
|
||||
|
||||
*Note: Indexes can only be created on models with one primary key*
|
||||
|
||||
:attr:`~cqlengine.columns.BaseColumn.db_field`
|
||||
Explicitly sets the name of the column in the database table. If this is left blank, the column name will be the same as the name of the column attribute. Defaults to None.
|
||||
|
||||
:attr:`~cqlengine.columns.BaseColumn.default`
|
||||
The default value for this column. If a model instance is saved without a value for this column having been defined, the default value will be used. This can be either a value or a callable object (ie: datetime.now is a valid default argument).
|
||||
|
||||
:attr:`~cqlengine.columns.BaseColumn.required`
|
||||
If True, this model cannot be saved without a value defined for this column. Defaults to True. Primary key fields cannot have their required fields set to False.
|
||||
|
||||
Model Methods
|
||||
=============
|
||||
Below are the methods that can be called on model instances.
|
||||
|
||||
.. class:: Model(\*\*values)
|
||||
|
||||
Creates an instance of the model. Pass in keyword arguments for columns you've defined on the model.
|
||||
|
||||
*Example*
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
#using the person model from earlier:
|
||||
class Person(Model):
|
||||
first_name = columns.Text()
|
||||
last_name = columns.Text()
|
||||
|
||||
person = Person(first_name='Blake', last_name='Eggleston')
|
||||
person.first_name #returns 'Blake'
|
||||
person.last_name #returns 'Eggleston'
|
||||
|
||||
|
||||
.. method:: save()
|
||||
|
||||
Saves an object to the database
|
||||
|
||||
*Example*
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
#create a person instance
|
||||
person = Person(first_name='Kimberly', last_name='Eggleston')
|
||||
#saves it to Cassandra
|
||||
person.save()
|
||||
|
||||
|
||||
.. method:: delete()
|
||||
|
||||
Deletes the object from the database.
|
||||
|
||||
Model Attributes
|
||||
================
|
||||
|
||||
.. attribute:: Model.db_name
|
||||
|
||||
*Optional.* Sets the name of the CQL table for this model. If left blank, the table name will be the name of the model, with it's module name as it's prefix
|
||||
|
||||
.. attribute:: Model.keyspace
|
||||
|
||||
*Optional.* Sets the name of the keyspace used by this model. Defaulst to cqlengine
|
||||
|
||||
Automatic Primary Keys
|
||||
======================
|
||||
CQL requires that all tables define at least one primary key. If a model definition does not include a primary key column, cqlengine will automatically add a uuid primary key column named ``id``.
|
||||
225
docs/topics/queryset.rst
Normal file
225
docs/topics/queryset.rst
Normal file
@@ -0,0 +1,225 @@
|
||||
==============
|
||||
Making Queries
|
||||
==============
|
||||
|
||||
.. module:: cqlengine.query
|
||||
|
||||
Retrieving objects
|
||||
==================
|
||||
Once you've populated Cassandra with data, you'll probably want to retrieve some of it. This is accomplished with QuerySet objects. This section will describe how to use QuerySet objects to retrieve the data you're looking for.
|
||||
|
||||
Retrieving all objects
|
||||
----------------------
|
||||
The simplest query you can make is to return all objects from a table.
|
||||
|
||||
This is accomplished with the ``.all()`` method, which returns a QuerySet of all objects in a table
|
||||
|
||||
Using the Person example model, we would get all Person objects like this:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
all_objects = Person.objects.all()
|
||||
|
||||
.. _retrieving-objects-with-filters:
|
||||
|
||||
Retrieving objects with filters
|
||||
----------------------------------------
|
||||
Typically, you'll want to query only a subset of the records in your database.
|
||||
|
||||
That can be accomplished with the QuerySet's ``.filter(\*\*)`` method.
|
||||
|
||||
For example, given the model definition:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
class Automobile(Model):
|
||||
manufacturer = columns.Text(primary_key=True)
|
||||
year = columns.Integer(primary_key=True)
|
||||
model = columns.Text()
|
||||
price = columns.Decimal()
|
||||
|
||||
...and assuming the Automobile table contains a record of every car model manufactured in the last 20 years or so, we can retrieve only the cars made by a single manufacturer like this:
|
||||
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
q = Automobile.objects.filter(manufacturer='Tesla')
|
||||
|
||||
We can then further filter our query with another call to **.filter**
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
q = q.filter(year=2012)
|
||||
|
||||
*Note: all queries involving any filtering MUST define either an '=' or an 'in' relation to either a primary key column, or an indexed column.*
|
||||
|
||||
Accessing objects in a QuerySet
|
||||
===============================
|
||||
|
||||
There are several methods for getting objects out of a queryset
|
||||
|
||||
* iterating over the queryset
|
||||
.. code-block:: python
|
||||
|
||||
for car in Automobile.objects.all():
|
||||
#...do something to the car instance
|
||||
pass
|
||||
|
||||
* list index
|
||||
.. code-block:: python
|
||||
|
||||
q = Automobile.objects.all()
|
||||
q[0] #returns the first result
|
||||
q[1] #returns the second result
|
||||
|
||||
|
||||
* list slicing
|
||||
.. code-block:: python
|
||||
|
||||
q = Automobile.objects.all()
|
||||
q[1:] #returns all results except the first
|
||||
q[1:9] #returns a slice of the results
|
||||
|
||||
*Note: CQL does not support specifying a start position in it's queries. Therefore, accessing elements using array indexing / slicing will load every result up to the index value requested*
|
||||
|
||||
* calling :attr:`get() <query.QuerySet.get>` on the queryset
|
||||
.. code-block:: python
|
||||
|
||||
q = Automobile.objects.filter(manufacturer='Tesla')
|
||||
q = q.filter(year=2012)
|
||||
car = q.get()
|
||||
|
||||
this returns the object matching the queryset
|
||||
|
||||
* calling :attr:`first() <query.QuerySet.first>` on the queryset
|
||||
.. code-block:: python
|
||||
|
||||
q = Automobile.objects.filter(manufacturer='Tesla')
|
||||
q = q.filter(year=2012)
|
||||
car = q.first()
|
||||
|
||||
this returns the first value in the queryset
|
||||
|
||||
.. _query-filtering-operators:
|
||||
|
||||
Filtering Operators
|
||||
===================
|
||||
|
||||
:attr:`Equal To <query.QueryOperator.EqualsOperator>`
|
||||
|
||||
The default filtering operator.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
q = Automobile.objects.filter(manufacturer='Tesla')
|
||||
q = q.filter(year=2012) #year == 2012
|
||||
|
||||
In addition to simple equal to queries, cqlengine also supports querying with other operators by appending a ``__<op>`` to the field name on the filtering call
|
||||
|
||||
:attr:`in (__in) <query.QueryOperator.InOperator>`
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
q = Automobile.objects.filter(manufacturer='Tesla')
|
||||
q = q.filter(year__in=[2011, 2012])
|
||||
|
||||
:attr:`> (__gt) <query.QueryOperator.GreaterThanOperator>`
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
q = Automobile.objects.filter(manufacturer='Tesla')
|
||||
q = q.filter(year__gt=2010) # year > 2010
|
||||
|
||||
:attr:`>= (__gte) <query.QueryOperator.GreaterThanOrEqualOperator>`
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
q = Automobile.objects.filter(manufacturer='Tesla')
|
||||
q = q.filter(year__gte=2010) # year >= 2010
|
||||
|
||||
:attr:`< (__lt) <query.QueryOperator.LessThanOperator>`
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
q = Automobile.objects.filter(manufacturer='Tesla')
|
||||
q = q.filter(year__lt=2012) # year < 2012
|
||||
|
||||
:attr:`<= (__lte) <query.QueryOperator.LessThanOrEqualOperator>`
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
q = Automobile.objects.filter(manufacturer='Tesla')
|
||||
q = q.filter(year__lte=2012) # year <= 2012
|
||||
|
||||
QuerySets are imutable
|
||||
======================
|
||||
|
||||
When calling any method that changes a queryset, the method does not actually change the queryset object it's called on, but returns a new queryset object with the attributes of the original queryset, plus the attributes added in the method call.
|
||||
|
||||
*Example*
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
#this produces 3 different querysets
|
||||
#q does not change after it's initial definition
|
||||
q = Automobiles.objects.filter(year=2012)
|
||||
tesla2012 = q.filter(manufacturer='Tesla')
|
||||
honda2012 = q.filter(manufacturer='Honda')
|
||||
|
||||
Ordering QuerySets
|
||||
==================
|
||||
|
||||
Since Cassandra is essentially a distributed hash table on steroids, the order you get records back in will not be particularly predictable.
|
||||
|
||||
However, you can set a column to order on with the ``.order_by(column_name)`` method.
|
||||
|
||||
*Example*
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
#sort ascending
|
||||
q = Automobiles.objects.all().order_by('year')
|
||||
#sort descending
|
||||
q = Automobiles.objects.all().order_by('-year')
|
||||
|
||||
*Note: Cassandra only supports ordering on a clustering key. In other words, to support ordering results, your model must have more than one primary key, and you must order on a primary key, excluding the first one.*
|
||||
|
||||
*For instance, given our Automobile model, year is the only column we can order on.*
|
||||
|
||||
QuerySet method reference
|
||||
=========================
|
||||
|
||||
.. class:: QuerySet
|
||||
|
||||
.. method:: all()
|
||||
|
||||
Returns a queryset matching all rows
|
||||
|
||||
.. method:: count()
|
||||
|
||||
Returns the number of matching rows in your QuerySet
|
||||
|
||||
.. method:: filter(\*\*values)
|
||||
|
||||
:param values: See :ref:`retrieving-objects-with-filters`
|
||||
|
||||
Returns a QuerySet filtered on the keyword arguments
|
||||
|
||||
.. method:: get(\*\*values)
|
||||
|
||||
:param values: See :ref:`retrieving-objects-with-filters`
|
||||
|
||||
Returns a single object matching the QuerySet. If no objects are matched, a :attr:`~models.Model.DoesNotExist` exception is raised. If more than one object is found, a :attr:`~models.Model.MultipleObjectsReturned` exception is raised.
|
||||
|
||||
.. method:: limit(num)
|
||||
|
||||
Limits the number of results returned by Cassandra.
|
||||
|
||||
*Note that CQL's default limit is 10,000, so all queries without a limit set explicitly will have an implicit limit of 10,000*
|
||||
|
||||
.. method:: order_by(field_name)
|
||||
|
||||
:param field_name: the name of the field to order on. *Note: the field_name must be a clustering key*
|
||||
:type field_name: string
|
||||
|
||||
Sets the field to order on.
|
||||
@@ -1,3 +1,4 @@
|
||||
cql==1.2.0
|
||||
ipython==0.13.1
|
||||
ipdb==0.7
|
||||
Sphinx==1.1.3
|
||||
|
||||
Reference in New Issue
Block a user