Builtin Modules
Builtin modules contains database agnostic utility for SQLite. Let's import builtins on your zig file.
Index
Create
Creates an user defined index for a given container field.
Remove
Removes an existing user defined index.
Index List
Gets all available indices from a given container.
const idxs = try Builtins.Index.getList(heap, &db, "users");
defer Builtins.Index.freeList(heap, idxs);
for (idxs) |idx| {
std.debug.print(
"Name: {s}\nSN: {d}\nOrigin: {any}\nUnique: {}\nPartial: {}\n\n",
.{idx.name, idx.sn, idx.origin, idx.unique, idx.partial}
);
}
Container
Rename
Renames an existing container. Be cautious about the existing code breakage.
Reset
Removes all records from a given container.
Delete
Permanently deletes a given container.
Add a New Field
Adds a new text fields to an existing container with NOT NULL and default value:
try Builtins.Container.fieldAdd(
&db, "users", "other1", .TEXT, .{.NotNull = "'Some Default Value'"}
);
Adds a new integer fields to an existing container with NOT NULL value:
Adds a new integer fields to an existing container with NULL value:
Rename an Existing Field
Renames an existing field name. Be cautious about the existing code breakage.
Remove an Existing Field
Removing an existing field is tricky because SQLite doesn't support it. However the following function uses a workaround for this. Be cautious about the existing code breakage.
FYI: This new Model schema should exclude the removable fields. For example, if the old model has a last_name field then the new model must exclude this last_name field to remove this from database.
Pragma
Schema Version
Returns current database schema version set by the user.
Update Schema Version
Sets the version number for the current database schema.
Cache
Returns database page cache.
Set Cache
Sets database page cache limits in kilobytes.
Page Count
Return total number of pages.
Page Size
Returns page size in bytes.
Set Page Size
Sets page size in bytes. Size must be the power of 2 (e.g., 4096, 8192, etc.).
Optimize
Optimizes the database.
Journal
Returns current journal mode.
Set Journal
Sets new journal mode.
Synchronous
Returns current synchronous mode.
Set Synchronous
Sets new synchronous mode.
Database Integrity
Checks internal consistency of the database file.
Reclaim Status
Returns the currently configured vacuum mode.
Set Reclaim Mode
Available options are NONE, INCREMENTAL, and FULL.
Claim Unused Space
Vacuums the database file for clean up any unused space.