Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions data/me.ppvan.psequel.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,13 @@
</description>
</key>

<key name="query-limit" type="i">
<default>200</default>
<summary>Select query limit</summary>
<description>
The limit of select query in the query, get 500 rows max for each query
</description>
</key>

</schema>
</schemalist>
2 changes: 2 additions & 0 deletions res/gtk/icons/left-large-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions res/gtk/icons/right-large-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 25 additions & 21 deletions res/gtk/query-view.blp
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,22 @@ template $PsequelQueryView : Adw.Bin {


}

Separator {}


Adw.ViewSwitcher tables_views_switcher {

styles ["big-icon"]
height-request: 40;
margin-start: 8;
margin-end: 8;
margin-top: 8;
// margin-bottom: 8;
margin-top: 4;
margin-bottom: 8;
policy: wide;
stack: sql_views;
}

Separator {}

Adw.ViewStack sql_views {
hexpand: true;
vexpand: true;
Expand Down Expand Up @@ -108,6 +109,8 @@ template $PsequelQueryView : Adw.Bin {
ListBox table_list {
styles ["navigation-sidebar"]
selected-rows-changed => $table_selected();
row-activated => $table_activated();
activate-on-single-click: false;
}

}
Expand Down Expand Up @@ -141,7 +144,7 @@ template $PsequelQueryView : Adw.Bin {

ToggleButton search_views_btn {
styles ["flat"]
tooltip-text: "Search tables";
tooltip-text: "Search views";
icon-name: "loupe-large-symbolic";

toggled => $on_show_view_search();
Expand All @@ -167,6 +170,7 @@ template $PsequelQueryView : Adw.Bin {
ListBox views_list {
styles ["navigation-sidebar"]
selected-rows-changed => $view_selected();
row-activated => $view_activated();
}
}
};
Expand All @@ -175,18 +179,13 @@ template $PsequelQueryView : Adw.Bin {

Box {
spacing: 4;
margin-bottom: 4;
margin-bottom: 8;
margin-end: 8;

Button logout {
Button {
styles ["flat"]
icon-name: "step-out-symbolic";
tooltip-text: "Logout";
clicked => $on_logout_clicked();
}

Label {
hexpand: true;
icon-name: "plus-large-symbolic";
tooltip-text: "Create new table";
}

Button reload {
Expand All @@ -197,12 +196,17 @@ template $PsequelQueryView : Adw.Bin {
clicked => $on_reload_clicked();
}

Button {
Label {
hexpand: true;
}

Button logout {
styles ["flat"]
icon-name: "plus-large-symbolic";
tooltip-text: "Create new table";
icon-name: "step-out-symbolic";
tooltip-text: "Logout";
clicked => $on_logout_clicked();
}

}
}

Expand Down Expand Up @@ -232,11 +236,11 @@ template $PsequelQueryView : Adw.Bin {
}

Adw.ViewStackPage {
name: "Data";
name: "data-view";
title: "Data";
icon-name: "object-rows-symbolic";
child: Label {
label: "Data";
child: $PsequelTableData {
};
}

Expand Down
85 changes: 85 additions & 0 deletions res/gtk/table-data.blp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using Gtk 4.0;

using Adw 1;

template $PsequelTableData : Gtk.Box {

width-request: 900;
height-request: 600;

orientation: vertical;
spacing: 4;
margin-start: 8;
margin-top: 8;
margin-end: 8;
margin-bottom: 8;

Box {
spacing: 12;
margin-top: 8;
margin-bottom: 8;
Entry filter_entry {
hexpand: true;
placeholder-text: "WHERE clause";
activate => $on_entry_activated();
}

Button filter_btn {
styles ["suggested-action"]
label: "Filter";

clicked => $filter_query();
}
}

ScrolledWindow {
ColumnView data_view {
show-row-separators: true;
show-column-separators: true;
styles ["data-table"]
vexpand: true;
}
}


Box {
spacing: 8;
// height-request: 40;
Button {
styles ["flat"]
icon-name: "plus-large-symbolic";
tooltip-text: "Insert Row";
}

Button reload {
styles ["flat"]
icon-name: "refresh-large-symbolic";
tooltip-text: "Reload Data";
clicked => $reload_data();
}

Separator {}

Label status_label {
label: "Rows 1 - 500";
hexpand: true;
halign: start;
}

Separator {}

Button left_page {
styles ["flat"]
icon-name: "left-large-symbolic";
tooltip-text: "Last Page";
clicked => $load_previous_page();
}

Button right_page {
styles ["flat"]
icon-name: "right-large-symbolic";
tooltip-text: "Next Page";
clicked => $load_next_page();
}
}
}
4 changes: 4 additions & 0 deletions res/gtk/table-structure.blp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ template $PsequelTableStructure : Gtk.Box {
}
ScrolledWindow {
ColumnView columns {

styles ["data-table"]
show-column-separators: true;
show-row-separators: true;
vexpand: true;
Expand All @@ -35,6 +37,7 @@ template $PsequelTableStructure : Gtk.Box {
ScrolledWindow {
ColumnView indexes {

styles ["data-table"]
show-column-separators: true;
show-row-separators: true;
vexpand: true;
Expand All @@ -50,6 +53,7 @@ template $PsequelTableStructure : Gtk.Box {
ScrolledWindow {
ColumnView foreign_key {

styles ["data-table"]
show-column-separators: true;
show-row-separators: true;
vexpand: true;
Expand Down
1 change: 1 addition & 0 deletions res/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ blueprints = custom_target('blueprints',
'gtk/connection-form.blp',
'gtk/query-view.blp',
'gtk/table-structure.blp',
'gtk/table-data.blp',
),
build_by_default: true,
# This does not run if you use an dot (.)
Expand Down
3 changes: 3 additions & 0 deletions res/psequel.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<file preprocess="xml-stripblanks">gtk/welcome.ui</file>
<file preprocess="xml-stripblanks">gtk/query-view.ui</file>
<file preprocess="xml-stripblanks">gtk/table-structure.ui</file>
<file preprocess="xml-stripblanks">gtk/table-data.ui</file>
<file preprocess="xml-stripblanks">gtk/recent-connection.ui</file>
<file preprocess="xml-stripblanks">gtk/connection-form.ui</file>
<file preprocess="xml-stripblanks">gtk/window.ui</file>
Expand All @@ -23,5 +24,7 @@
<file preprocess="xml-stripblanks" alias="step-out-symbolic.svg">gtk/icons/step-out-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="arrow-into-box-symbolic.svg">gtk/icons/arrow-into-box-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="category-search-symbolic.svg">gtk/icons/category-search-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="left-large-symbolic.svg">gtk/icons/left-large-symbolic.svg</file>
<file preprocess="xml-stripblanks" alias="right-large-symbolic.svg">gtk/icons/right-large-symbolic.svg</file>
</gresource>
</gresources>
3 changes: 2 additions & 1 deletion src/application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace Psequel {

try {
background = new ThreadPool<Worker>.with_owned_data ((worker) => {
worker.task ();
worker.run ();
}, ResourceManager.POOL_SIZE, false);
} catch (ThreadError err) {
debug (err.message);
Expand Down Expand Up @@ -94,6 +94,7 @@ namespace Psequel {
typeof (Psequel.ConnectionForm).ensure ();
typeof (Psequel.QueryView).ensure ();
typeof (Psequel.TableStructure).ensure ();
typeof (Psequel.TableData).ensure ();
}
}
}
1 change: 1 addition & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ psequel_sources = [
'ui/window.vala',
'ui/query_view.vala',
'ui/table_structure.vala',
'ui/table_data.vala',
'models/connection.vala',
'models/schema.vala',
'models/table.vala',
Expand Down
61 changes: 60 additions & 1 deletion src/models/table.vala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Psequel {

private ArrayList<Row> data;
private ArrayList<string> headers;
private ArrayList<Type> cols_type;

public Relation (owned Result res) {
Object ();
Expand All @@ -23,6 +24,16 @@ namespace Psequel {
this.data = data;
this.rows = data.size;
this.cols = headers.size;

this.cols_type = new ArrayList<Type> ();
// Fix me in the future
for (int i = 0; i < headers.size; i++) {
this.cols_type.add (Type.STRING);
}
}

public Type get_column_type (int index) {
return this.cols_type[index];
}

private void load_data (owned Result result) {
Expand All @@ -32,14 +43,51 @@ namespace Psequel {
cols = result.get_n_fields ();

this.headers = new ArrayList<string> ();
this.cols_type = new ArrayList<Type> ();
for (int i = 0; i < cols; i++) {

// Oid, should have enum for value type in VAPI but no.
switch ((uint)result.get_field_type (i)) {
case 20, 21, 23:
// int
this.cols_type.add (Type.INT64);
break;
case 16:
// bool
this.cols_type.add (Type.BOOLEAN);
break;
case 700, 701:
// real
this.cols_type.add (Type.DOUBLE);
break;
case 25, 1043, 18, 19, 1700:
// string
this.cols_type.add (Type.STRING);
break;
case 1114:
// timestamp
this.cols_type.add (Type.STRING);
break;
case 1082:
// date
this.cols_type.add (Type.STRING);
break;

default:
debug ("Programming errors, unhandled Oid: %u", (uint)result.get_field_type (i));
this.cols_type.add (Type.STRING);
break;
// assert_not_reached ();
}

headers.add (result.get_field_name (i));
}

this.data = new ArrayList<Row> ();

for (int i = 0; i < rows; i++) {
data.add (new Row ());

for (int j = 0; j < cols; j++) {
data[i].add_field (result.get_value (i, j));
}
Expand All @@ -58,6 +106,14 @@ namespace Psequel {
return new Relation.from_data (new_headers, new_rows);
}

public string get_header (int index) {
if (index >= cols) {
return "";
}

return headers.get (index);
}

public string to_string () {
return @"Table ($rows x $cols)";
}
Expand Down Expand Up @@ -104,7 +160,10 @@ namespace Psequel {
data.remove_at (index);
}

public new string @get (int index) {
public new string? @get (int index) {
if (index >= size) {
return null;
}
return data.get (index);
}

Expand Down
Loading