How to use the jardin.query.query function in jardin

To help you get started, we’ve selected a few jardin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github instacart / jardin / tests / __init__.py View on Github external
def setup(self):
        self.teardown()
        if self._connection.db_config.scheme == 'sqlite':
            query(
                sql='CREATE TABLE %s (id INTEGER PRIMARY KEY AUTOINCREMENT, name varchar(256), created_at timestamp NULL, updated_at timestamp NULL, deleted_at timestamp NULL, destroyed_at timestamp NULL, num decimal);' % self._model._table_name(),
                db='jardin_test'
                )
        else:
            query(
                sql='CREATE TABLE %s (id serial PRIMARY KEY, name varchar(256), created_at timestamp NULL, updated_at timestamp NULL, deleted_at timestamp NULL, destroyed_at timestamp NULL, num decimal);' % self._model._table_name(),
                db='jardin_test'
                )
github instacart / jardin / tests / test_insert.py View on Github external
def test_pg_array(self):
        User.clear_caches()
        query(
            'CREATE TABLE users (id SERIAL PRIMARY KEY, ids TEXT ARRAY);',
            db='jardin_test'
            )
        self.assertEqual(User.count(), 0)
        User.insert(
            values={'ids': ['a', 'b', 'c']}
            )
        self.assertEqual(User.count(), 1)
github instacart / jardin / tests / test_insert.py View on Github external
def test_pg_jsonb_list(self):
        User.clear_caches()
        query(
            'CREATE TABLE users (id SERIAL PRIMARY KEY, ids JSONB);',
            db='jardin_test'
            )
        self.assertEqual(User.count(), 0)
        User.insert(
            values={'ids': ['a', 'b', 'c']}
            )
        self.assertEqual(User.count(), 1)
github instacart / jardin / jardin / model.py View on Github external
def query(self, sql=None, filename=None, **kwargs):
        """ run raw sql from sql or file against.

        :param sql: Raw SQL query to pass directly to the connection.
        :type sql: string
        :param filename: Path to a file containing a SQL query. The path should be relative to CWD.
        :type filename: string
        :param db: `optional` Database name from your ``jardin_conf.py``, overrides the default database set in the model declaration.
        :type db: string
        :param role: `optional` One of ``('master', 'replica')`` to override the default.
        :type role: string
        :returns: ``jardin.Collection`` collection, which is a ``pandas.DataFrame``.
        """
        results = query(
            sql=sql,
            filename=filename,
            db=self.db_names[kwargs.get('role', 'replica')],
            **kwargs
            )

        if results is None:
            return None
        else:
            return self.collection_instance(results)