diff --git a/.credo.exs b/.credo.exs new file mode 100644 index 0000000..d1c2d76 --- /dev/null +++ b/.credo.exs @@ -0,0 +1,11 @@ +%{ + configs: [ + %{ + name: "default", + strict: true, + checks: [ + {Credo.Check.Design.TagTODO, false}, + ] + } + ] +} diff --git a/README.md b/README.md index 4d166b5..08335ef 100644 --- a/README.md +++ b/README.md @@ -41,16 +41,16 @@ EctoSQLite3Extras.table_size({MyProject.Repo, self()}) ## Available queries -1. `total_size`. Total size of all tables and indices. It's a summary talbe, it has only 2 columns: `name` and `value`. Rows: +1. `total_size`. The total size of all tables and indices. It's a summary table, it has only 2 columns: `name` and `value`. Rows: 1. `cells`: The number of cells in the DB. Each value stored in the DB is represented as at least one cell. So, the number of cells correlates with the number of records in the DB. 1. `payload_size`: How much space the actual useful payload takes in the DB. 1. `unused_size`: How much space in the DB is reserved, not used yet, and can be used later to store more data. This is a surplus that occurs because SQLite allocates space for data in chunks ("pages"). - 1. `vacuum_size`: How much space is unused and cannot be used for the future data. You can run [VACUUM](https://www.sqlite.org/lang_vacuum.html) command to reduce it. + 1. `vacuum_size`: How much space is unused and cannot be used for future data. You can run [VACUUM](https://www.sqlite.org/lang_vacuum.html) command to reduce it. 1. `page_size`: The total space occupied by all pages. Each page is a single chunk of space allocated by SQLite. This number is the sum of `payload_size`, `unused_size`, and `vacuum_size`. 1. `pages`: The total number of pages. 1. `pages: leaf`: The pages that store the actual data. Read [SQLite Internals: Pages & B-trees](https://fly.io/blog/sqlite-internals-btree/) to learn more. 1. `pages: internal`: The pages that store ranges for leaf pages for a faster lookup. Sometimes also called "interior pages". - 1. `pages: overflow`: The pages that store chunks of big data that doesn't fit in a single leaf page. + 1. `pages: overflow`: The pages that store chunks of big data that don't fit in a single leaf page. 1. `pages: table`: The pages used for storing data for tables. 1. `pages: index`: The pages used for storing indices. 1. `table_size`. Information about the space used (and unused) by all tables. Based on the [dbstat](https://www.sqlite.org/dbstat.html) virtual table. @@ -65,7 +65,7 @@ EctoSQLite3Extras.table_size({MyProject.Repo, self()}) 1. `index_size`. Size of all indices. 1. `name`: The index name. 1. `table_name`: The table where the index is defined. - 1. `column_name`: The name of the column being indexed. This columns is NULL if the column is the rowid or an expression. + 1. `column_name`: The name of the column being indexed. This column is NULL if the column is the rowid or an expression. 1. `payload_size`. 1. `unused_size`. 1. `page_size`. @@ -75,7 +75,7 @@ EctoSQLite3Extras.table_size({MyProject.Repo, self()}) 1. `sequence_number`. Sequence numbers of autoincrement columns. Generated based on the [sqlite_sequence](https://renenyffenegger.ch/notes/development/databases/SQLite/internals/schema-objects/sqlite_sequence) table. The query will fail if there are no autoincrement columns in the DB yet. 1. `table_name`. 1. `sequence_number`. -1. `pragma`. List values of PRAGMAs (settings). Only includes the ones that have an integer or a boolean value. For bravity, the ones with `0` (`false`) value are excluded from the output (based on the observation that this is the default value for most of the PRAGMAs). Check out the SQLite documentation to learn more about what each PRAGMA means: [PRAGMA Statements](https://www.sqlite.org/pragma.html). +1. `pragma`. List values of PRAGMAs (settings). Only includes the ones that have an integer or a boolean value. For brevity, the ones with the `0` (`false`) value are excluded from the output (based on the observation that this is the default value for most of the PRAGMAs). Check out the SQLite documentation to learn more about what each PRAGMA means: [PRAGMA Statements](https://www.sqlite.org/pragma.html). 1. `name`: the name of the PRAGMA as listed in the SQLite documentation. 1. `value`: the value of the PRAGMA. The `true` value is converted into `1` (and `false` is simply excluded). 1. `integrity_check`. Run integrity checks on the database. Executes [PRAGMA integrity_check](https://www.sqlite.org/pragma.html#pragma_integrity_check) and returns the resulting messages. diff --git a/lib/ecto_sqlite3_extras.ex b/lib/ecto_sqlite3_extras.ex index 8f95769..06adfe1 100644 --- a/lib/ecto_sqlite3_extras.ex +++ b/lib/ecto_sqlite3_extras.ex @@ -48,6 +48,8 @@ defmodule EctoSQLite3Extras do @doc """ Sequence numbers of autoincrement columns. + + The query will fail if there are no autoincrement columns in the DB yet. """ @spec sequence_number(repo(), keyword()) :: any() def sequence_number(repo, opts \\ []), do: query(:sequence_number, repo, opts) diff --git a/lib/queries/sequence_number.ex b/lib/queries/sequence_number.ex index e6c2903..61287be 100644 --- a/lib/queries/sequence_number.ex +++ b/lib/queries/sequence_number.ex @@ -16,6 +16,9 @@ defmodule EctoSQLite3Extras.SequenceNumber do } end + # TODO(@orsinium): The query fails if the table doesn't exist. + # The table is created only when the first autoincrement column is created. + # Can we fix it without doing INSERTs? def query(_args \\ []) do """ /* from ecto_sqlite3_extras */ diff --git a/lib/queries/total_size.ex b/lib/queries/total_size.ex index 5df75fe..2b9bb41 100644 --- a/lib/queries/total_size.ex +++ b/lib/queries/total_size.ex @@ -25,7 +25,6 @@ defmodule EctoSQLite3Extras.TotalSize do UNION ALL SELECT 'unused_size', SUM(unused) FROM dbstat UNION ALL SELECT 'vacuum_size', SUM(pgsize) - SUM(payload) - SUM(unused) FROM dbstat UNION ALL SELECT 'page_size', SUM(pgsize) FROM dbstat - UNION ALL SELECT 'pages', COUNT(*) FROM dbstat UNION ALL SELECT 'pages: leaf', COUNT(*) FROM dbstat WHERE pagetype = 'leaf' diff --git a/mix.exs b/mix.exs index d62dfea..3319ea0 100644 --- a/mix.exs +++ b/mix.exs @@ -1,7 +1,7 @@ defmodule EctoSQLite3Extras.MixProject do use Mix.Project @github_url "https://github.com/orsinium-labs/ecto_sqlite3_extras" - @version "1.1.5" + @version "1.1.6" def project do [ diff --git a/test/ecto_sqlite3_extras_test.exs b/test/ecto_sqlite3_extras_test.exs index c9fa1af..8c614be 100644 --- a/test/ecto_sqlite3_extras_test.exs +++ b/test/ecto_sqlite3_extras_test.exs @@ -55,7 +55,6 @@ defmodule EctoSQLite3ExtrasTest do ["unused_size", "82.0 KB"], ["vacuum_size", "184.8 KB"], ["page_size", "864.0 KB"], - ["pages", 864], ["pages: leaf", 840], ["pages: internal", 24], ["pages: overflow", 0],