{"html_url": "https://github.com/simonw/sqlite-utils/issues/539#issuecomment-1537507394", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/539", "id": 1537507394, "node_id": "IC_kwDOCGYnMM5bpIBC", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-05-07T18:08:44Z", "updated_at": "2023-05-07T18:08:44Z", "author_association": "OWNER", "body": "Prototype:\r\n```diff\r\ndiff --git a/docs/cli-reference.rst b/docs/cli-reference.rst\r\nindex 153e5f9..c830518 100644\r\n--- a/docs/cli-reference.rst\r\n+++ b/docs/cli-reference.rst\r\n@@ -124,6 +124,7 @@ See :ref:`cli_query`.\r\n --json-cols Detect JSON cols and output them as JSON, not\r\n escaped strings\r\n -r, --raw Raw output, first column of first row\r\n+ --raw-lines Raw output, first column of each row\r\n -p, --param ... Named :parameters for SQL query\r\n --functions TEXT Python code defining one or more custom SQL\r\n functions\r\n@@ -192,6 +193,7 @@ See :ref:`cli_memory`.\r\n --json-cols Detect JSON cols and output them as JSON, not\r\n escaped strings\r\n -r, --raw Raw output, first column of first row\r\n+ --raw-lines Raw output, first column of each row\r\n -p, --param ... Named :parameters for SQL query\r\n --encoding TEXT Character encoding for CSV input, defaults to\r\n utf-8\r\ndiff --git a/sqlite_utils/cli.py b/sqlite_utils/cli.py\r\nindex d25b1df..da0e4b6 100644\r\n--- a/sqlite_utils/cli.py\r\n+++ b/sqlite_utils/cli.py\r\n@@ -1653,6 +1653,7 @@ def drop_view(path, view, ignore, load_extension):\r\n )\r\n @output_options\r\n @click.option(\"-r\", \"--raw\", is_flag=True, help=\"Raw output, first column of first row\")\r\n+@click.option(\"--raw-lines\", is_flag=True, help=\"Raw output, first column of each row\")\r\n @click.option(\r\n \"-p\",\r\n \"--param\",\r\n@@ -1677,6 +1678,7 @@ def query(\r\n fmt,\r\n json_cols,\r\n raw,\r\n+ raw_lines,\r\n param,\r\n load_extension,\r\n functions,\r\n@@ -1700,7 +1702,19 @@ def query(\r\n _register_functions(db, functions)\r\n \r\n _execute_query(\r\n- db, sql, param, raw, table, csv, tsv, no_headers, fmt, nl, arrays, json_cols\r\n+ db,\r\n+ sql,\r\n+ param,\r\n+ raw,\r\n+ raw_lines,\r\n+ table,\r\n+ csv,\r\n+ tsv,\r\n+ no_headers,\r\n+ fmt,\r\n+ nl,\r\n+ arrays,\r\n+ json_cols,\r\n )\r\n \r\n \r\n@@ -1728,6 +1742,7 @@ def query(\r\n )\r\n @output_options\r\n @click.option(\"-r\", \"--raw\", is_flag=True, help=\"Raw output, first column of first row\")\r\n+@click.option(\"--raw-lines\", is_flag=True, help=\"Raw output, first column of each row\")\r\n @click.option(\r\n \"-p\",\r\n \"--param\",\r\n@@ -1773,6 +1788,7 @@ def memory(\r\n fmt,\r\n json_cols,\r\n raw,\r\n+ raw_lines,\r\n param,\r\n encoding,\r\n no_detect_types,\r\n@@ -1879,12 +1895,36 @@ def memory(\r\n _register_functions(db, functions)\r\n \r\n _execute_query(\r\n- db, sql, param, raw, table, csv, tsv, no_headers, fmt, nl, arrays, json_cols\r\n+ db,\r\n+ sql,\r\n+ param,\r\n+ raw,\r\n+ raw_lines,\r\n+ table,\r\n+ csv,\r\n+ tsv,\r\n+ no_headers,\r\n+ fmt,\r\n+ nl,\r\n+ arrays,\r\n+ json_cols,\r\n )\r\n \r\n \r\n def _execute_query(\r\n- db, sql, param, raw, table, csv, tsv, no_headers, fmt, nl, arrays, json_cols\r\n+ db,\r\n+ sql,\r\n+ param,\r\n+ raw,\r\n+ raw_lines,\r\n+ table,\r\n+ csv,\r\n+ tsv,\r\n+ no_headers,\r\n+ fmt,\r\n+ nl,\r\n+ arrays,\r\n+ json_cols,\r\n ):\r\n with db.conn:\r\n try:\r\n@@ -1903,6 +1943,13 @@ def _execute_query(\r\n sys.stdout.buffer.write(data)\r\n else:\r\n sys.stdout.write(str(data))\r\n+ elif raw_lines:\r\n+ for row in cursor:\r\n+ data = row[0]\r\n+ if isinstance(data, bytes):\r\n+ sys.stdout.buffer.write(data + b\"\\n\")\r\n+ else:\r\n+ sys.stdout.write(str(data) + \"\\n\")\r\n elif fmt or table:\r\n print(\r\n tabulate.tabulate(\r\n```\r\nNeeds tests and more documentation.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1699174055, "label": "`--raw-lines` option, like `--raw` for multiple lines"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/539#issuecomment-1537507525", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/539", "id": 1537507525, "node_id": "IC_kwDOCGYnMM5bpIDF", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-05-07T18:09:09Z", "updated_at": "2023-05-07T18:09:09Z", "author_association": "OWNER", "body": "I'm tempted to upgrade `--raw` to do this instead, but that would be a breaking change.", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1699174055, "label": "`--raw-lines` option, like `--raw` for multiple lines"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/539#issuecomment-1537507676", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/539", "id": 1537507676, "node_id": "IC_kwDOCGYnMM5bpIFc", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-05-07T18:09:43Z", "updated_at": "2023-05-07T18:09:54Z", "author_association": "OWNER", "body": "This worked:\r\n\r\n```bash\r\nsqlite-utils memory /tmp/books3.json:nl \\\r\n 'select name from books3' --raw-lines > titles.txt\r\n```", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1699174055, "label": "`--raw-lines` option, like `--raw` for multiple lines"}, "performed_via_github_app": null} {"html_url": "https://github.com/simonw/sqlite-utils/issues/539#issuecomment-1537514610", "issue_url": "https://api.github.com/repos/simonw/sqlite-utils/issues/539", "id": 1537514610, "node_id": "IC_kwDOCGYnMM5bpJxy", "user": {"value": 9599, "label": "simonw"}, "created_at": "2023-05-07T18:43:24Z", "updated_at": "2023-05-07T18:43:24Z", "author_association": "OWNER", "body": "Documentation:\r\n- https://sqlite-utils.datasette.io/en/latest/cli.html#returning-raw-data-such-as-binary-content\r\n- https://sqlite-utils.datasette.io/en/latest/cli-reference.html#query\r\n- https://sqlite-utils.datasette.io/en/latest/cli-reference.html#memory", "reactions": "{\"total_count\": 0, \"+1\": 0, \"-1\": 0, \"laugh\": 0, \"hooray\": 0, \"confused\": 0, \"heart\": 0, \"rocket\": 0, \"eyes\": 0}", "issue": {"value": 1699174055, "label": "`--raw-lines` option, like `--raw` for multiple lines"}, "performed_via_github_app": null}