aboutsummaryrefslogtreecommitdiff
path: root/qlite/src/table.vala
diff options
context:
space:
mode:
Diffstat (limited to 'qlite/src/table.vala')
-rw-r--r--qlite/src/table.vala23
1 files changed, 23 insertions, 0 deletions
diff --git a/qlite/src/table.vala b/qlite/src/table.vala
index b4f2fee7..bd3fcc36 100644
--- a/qlite/src/table.vala
+++ b/qlite/src/table.vala
@@ -7,6 +7,7 @@ public class Table {
public string name { get; private set; }
protected Column[]? columns;
private string constraints = "";
+ private string[] post_statements = {};
public Table(Database db, string name) {
this.db = db;
@@ -32,6 +33,22 @@ public class Table {
}
}
+ public void add_post_statement(string stmt) {
+ post_statements += stmt;
+ }
+
+ public void index(string index_name, Column[] columns, bool unique = false) {
+ string stmt = @"CREATE $(unique ? "UNIQUE" : "") INDEX IF NOT EXISTS $index_name ON $name (";
+ bool first = true;
+ foreach (Column c in columns) {
+ if (!first) stmt += ", ";
+ stmt += c.name;
+ first = false;
+ }
+ stmt += ")";
+ add_post_statement(stmt);
+ }
+
private void ensure_init() throws DatabaseError {
if (columns == null) throw new DatabaseError.NOT_INITIALIZED(@"Table $name was not initialized, call init()");
}
@@ -114,6 +131,12 @@ public class Table {
db.exec(@"DROP TABLE _$(name)_$old_version");
}
}
+
+ internal void post() throws DatabaseError {
+ foreach (string stmt in post_statements) {
+ db.exec(stmt);
+ }
+ }
}
} \ No newline at end of file