Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/src/piccolo/getting_started/playground.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ A ``piccolo.sqlite`` file will get created in the current directory.
Advanced usage
---------------

To see how to use the playground with Postgres, and other advanced usage, see
:ref:`PlaygroundAdvanced`.
To see how to use the playground with Postgres or Cockroach, and other
advanced usage, see :ref:`PlaygroundAdvanced`.

-------------------------------------------------------------------------------

Expand Down
50 changes: 50 additions & 0 deletions docs/src/piccolo/playground/advanced.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,56 @@ When you have the database setup, you can connect to it as follows:

piccolo playground run --engine=postgres

CockroachDB
-----------

If you want to use CockroachDB instead of SQLite, you need to create a database
first.


Install CockroachDB
~~~~~~~~~~~~~~~~~~~

See the `installation guide for your OS <https://www.cockroachlabs.com/docs/v25.2/install-cockroachdb-linux/>`_.

Create database
~~~~~~~~~~~~~~~
The playground is for testing and learning purposes only, so you can start a CockroachDB
`single node with the insecure flag <https://www.cockroachlabs.com/docs/v25.2/cockroach-start-single-node.html/>`_
(for non-production testing only) like this:

.. code-block:: bash

cockroach start-single-node --insecure

After that, in a new terminal window, you can create a database like this:

.. code-block:: bash

cockroach sql --insecure --execute="DROP DATABASE IF EXISTS piccolo_playground CASCADE;CREATE DATABASE piccolo_playground;"

By default the playground expects a local database to exist with the following
credentials:


.. code-block:: bash

user: "root"
password: ""
host: "localhost" # or 127.0.0.1
database: "piccolo_playground"
port: 26257


Connecting
~~~~~~~~~~

When you have the database setup, you can connect to it as follows:

.. code-block:: bash

piccolo playground run --engine=cockroach

iPython
-------

Expand Down
38 changes: 25 additions & 13 deletions piccolo/apps/playground/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import uuid
from decimal import Decimal
from enum import Enum
from typing import Optional

from piccolo.columns import (
JSON,
Expand All @@ -25,7 +26,7 @@
Varchar,
)
from piccolo.columns.readable import Readable
from piccolo.engine import PostgresEngine, SQLiteEngine
from piccolo.engine import CockroachEngine, PostgresEngine, SQLiteEngine
from piccolo.engine.base import Engine
from piccolo.table import Table
from piccolo.utils.warnings import colored_string
Expand Down Expand Up @@ -284,28 +285,29 @@ def populate():

def run(
engine: str = "sqlite",
user: str = "piccolo",
password: str = "piccolo",
user: Optional[str] = None,
password: Optional[str] = None,
database: str = "piccolo_playground",
host: str = "localhost",
port: int = 5432,
port: Optional[int] = None,
ipython_profile: bool = False,
):
"""
Creates a test database to play with.

:param engine:
Which database engine to use - options are sqlite or postgres
Which database engine to use - options are sqlite, postgres or
cockroach
:param user:
Postgres user
Database user (ignored for SQLite)
:param password:
Postgres password
Database password (ignored for SQLite)
:param database:
Postgres database
Database name (ignored for SQLite)
:param host:
Postgres host
Database host (ignored for SQLite)
:param port:
Postgres port
Database port (ignored for SQLite)
:param ipython_profile:
Set to true to use your own IPython profile. Located at ~/.ipython/.
For more info see the IPython docs
Expand All @@ -324,9 +326,19 @@ def run(
{
"host": host,
"database": database,
"user": user,
"password": password,
"port": port,
"user": user or "piccolo",
"password": password or "piccolo",
"port": port or 5432,
}
)
elif engine.upper() == "COCKROACH":
db = CockroachEngine(
{
"host": host,
"database": database,
"user": user or "root",
"password": password or "",
"port": port or 26257,
}
)
else:
Expand Down