You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+50-16Lines changed: 50 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,45 +9,79 @@ The package can be installed by adding `ecto_sqlite3_extras` to your list of dep
9
9
```elixir
10
10
defdepsdo
11
11
[
12
-
{:ecto_sqlite3_extras, "~> 1.0.0"}
12
+
{:ecto_sqlite3_extras, "~> 1.1.5"}
13
13
]
14
14
end
15
15
```
16
16
17
17
## Integrating with Phoenix Live Dashboard
18
18
19
-
...
19
+
When you have `ecto_sqlite3_extras` in the list of dependencies for your [Phoenix](https://www.phoenixframework.org/) project that uses [ecto_sqlite3](https://github.com/elixir-sqlite/ecto_sqlite3), the [Phoenix Live Dashboard](https://github.com/phoenixframework/phoenix_live_dashboard) will automatically show the tables produced by `ecto_sqlite3_extras` in the "Ecto Stats" tab. Magic!
20
20
21
21

22
22
23
23
## Using from Elixir
24
24
25
-
...
25
+
If you don't have Phoenix Live Dashboard on the environment you want to inspect, you can use `ecto_sqlite3_extras` directly from the [iex](https://hexdocs.pm/iex/1.14/IEx.html) shell.
26
+
27
+
```elixir
28
+
# run the query and print a nice ASCII table into stdout

28
39
29
40
## Available queries
30
41
42
+
1.`total_size`. Total size of all tables and indices. It's a summary talbe, it has only 2 columns: `name` and `value`. Rows:
43
+
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.
44
+
1.`payload_size`: How much space the actual useful payload takes in the DB.
45
+
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").
46
+
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.
47
+
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`.
48
+
1.`pages`: The total number of pages.
49
+
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.
50
+
1.`pages: internal`: The pages that store ranges for leaf pages for a faster lookup. Sometimes also called "interior pages".
51
+
1.`pages: overflow`: The pages that store chunks of big data that doesn't fit in a single leaf page.
52
+
1.`pages: table`: The pages used for storing data for tables.
53
+
1.`pages: index`: The pages used for storing indices.
31
54
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.
32
-
1.`name`: the table name.
33
-
1.`payload_size`:
34
-
1.`unused_size`:
35
-
1.`page_size`:
36
-
1.`cells`:
37
-
1.`pages`:
38
-
1.`max_payload_size`:
39
-
1.`index_size`.
40
-
1.`sequence_number`.
41
-
1.`table_name`:
42
-
1.`sequence_number`:
43
-
1.`settings`. 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).
55
+
1.`name`: The table name.
56
+
1.`payload_size`.
57
+
1.`unused_size`.
58
+
1.`vacuum_size`.
59
+
1.`page_size`.
60
+
1.`cells`.
61
+
1.`pages`.
62
+
1.`max_payload_size`: The size of the biggest payload in the table.
63
+
1.`index_size`. Size of all indices.
64
+
1.`name`: The index name.
65
+
1.`table_name`: The table where the index is defined.
66
+
1.`column_name`: The name of the column being indexed. This columns is NULL if the column is the rowid or an expression.
67
+
1.`payload_size`.
68
+
1.`unused_size`.
69
+
1.`page_size`.
70
+
1.`cells`.
71
+
1.`pages`.
72
+
1.`max_payload_size`.
73
+
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.
74
+
1.`table_name`.
75
+
1.`sequence_number`.
76
+
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).
44
77
1.`name`: the name of the PRAGMA as listed in the SQLite documentation.
45
78
1.`value`: the value of the PRAGMA. The `true` value is converted into `1` (and `false` is simply excluded).
79
+
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.
46
80
47
81
## Acknowledgments
48
82
49
83
These are the projects that made `ecto_sqlite3_extras` possible:
50
84
51
85
1.[phoenix_live_dashboard](https://github.com/phoenixframework/phoenix_live_dashboard) is the reason why I made the project. I want my SQLite-powered Phoenix service to have the same nice-looking live dashboard as for PostgreSQL.
52
-
1.[exqlite](https://github.com/elixir-sqlite/exqlite) provides SQLite support for Elixir. They enabled just for me the `SQLITE_ENABLE_DBSTAT_VTAB` option required for `ecto_sqlite3_extras` to work, literally making this project possible.
86
+
1.[exqlite](https://github.com/elixir-sqlite/exqlite) provides SQLite support for Elixir. They [enabled just for me](https://github.com/elixir-sqlite/exqlite/issues/231) the `SQLITE_ENABLE_DBSTAT_VTAB` option required for `ecto_sqlite3_extras` to work, literally making this project possible.
53
87
1.[ecto_psql_extras](https://github.com/pawurb/ecto_psql_extras) is a similar project for PostgreSQL. I shamelessly copied the project structure and tests, so that I can be sure that `ecto_sqlite3_extras` can be a drop-in replacement for `ecto_psql_extras`.
0 commit comments