'Create a new query.
:<json number data_source_id: The ID of the data source this query will run on
:<json string query: Query text
:<json string name:
:<json string description:
:<json string schedule: Schedule interval, in seconds, for repeated execution of this query
:<json object options: Query options
.. _query-response-label:
:>json number id: Query ID
:>json number latest_query_data_id: ID for latest output data from this query
:>json string name:
:>json string description:
:>json string query: Query text
:>json string query_hash: Hash of query text
:>json string schedule: Schedule interval, in seconds, for repeated execution of this query
:>json string api_key: Key for public access to this query\'s results.
:>json boolean is_archived: Whether this query is displayed in indexes and search results or not.
:>json boolean is_draft: Whether this query is a draft or not
:>json string updated_at: Time of last modification, in ISO format
:>json string created_at: Time of creation, in ISO format
:>json number data_source_id: ID of the data source this query will run on
:>json object options: Query options
:>json number version: Revision version (for update conflict avoidance)
:>json number user_id: ID of query creator
:>json number last_modified_by_id: ID of user who last modified this query
:>json string retrieved_at: Time when query results were last retrieved, in ISO format (may be null)
:>json number runtime: Runtime of last query execution, in seconds (may be null)'

@require_permission('create_query')
def post(self):

    query_def = request.get_json(force=True)
    data_source = models.DataSource.get_by_id_and_org(query_def.pop('data_source_id'), self.current_org)
    require_access(data_source.groups, self.current_user, not_view_only)
    for field in ['id', 'created_at', 'api_key', 'visualizations', 'latest_query_data', 'last_modified_by']:
        query_def.pop(field, None)
    query_def['query_text'] = query_def.pop('query')
    query_def['user'] = self.current_user
    query_def['data_source'] = data_source
    query_def['org'] = self.current_org
    query_def['is_draft'] = True
    query = models.Query.create(**query_def)
    models.db.session.add(query)
    models.db.session.commit()
    self.record_event({'action': 'create', 'object_id': query.id, 'object_type': 'query'})
    return query.to_dict()
