Skip to content

Commit c47cfce

Browse files
committed
Merge branch 'master' of https://github.com/spaceuptech/space-cloud into ee-v0.9.0
2 parents e9142dc + b2198a2 commit c47cfce

36 files changed

+3048
-273
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
.idea
2+
.vscode
3+
14
# Binaries for programs and plugins
25
*.exe
36
*.exe~

docs/manual/database/create.md

+105-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ You can add data to your app by simply calling `db.insert` on the frontend. Here
88
<li class="tab col s2"><a class="active" href="#insert-js">Javascript</a></li>
99
<li class="tab col s2"><a href="#insert-java">Java</a></li>
1010
<li class="tab col s2"><a href="#insert-python">Python</a></li>
11+
<li class="tab col s2"><a href="#insert-golang">Golang</a></li>
1112
</ul>
1213
</div>
1314
<div id="insert-js" class="col s12" style="padding:0">
@@ -41,7 +42,25 @@ db.insert("todos").doc(doc).apply()
4142
<div id="insert-java" class="col s12" style="padding:0">
4243
<pre>
4344
<code class="java">
44-
// Java client coming soon!
45+
API api = new API("books-app", "localhost", 8081);
46+
SQL db = api.MySQL();
47+
Map<String, String> document = new HashMap<>();
48+
document.put("name", "aBook");
49+
db.insert("books").doc(document).apply(new Utils.ResponseListener() {
50+
@Override
51+
public void onResponse(int statusCode, Response response) {
52+
if (statusCode == 200) {
53+
System.out.println("Success");
54+
} else {
55+
System.out.println(response.getError());
56+
}
57+
}
58+
59+
@Override
60+
public void onError(Exception e) {
61+
System.out.println(e.getMessage());
62+
}
63+
});
4564
</code>
4665
</pre>
4766
</div>
@@ -69,6 +88,35 @@ api.close()
6988
</code>
7089
</pre>
7190
</div>
91+
<div id="insert-golang" class="col s12" style="padding:0">
92+
<pre>
93+
<code class="golang">
94+
import (
95+
"github.com/spaceuptech/space-api-go/api"
96+
"fmt"
97+
)
98+
99+
func main() {
100+
api, err := api.Init("books-app", "localhost", "8081", false)
101+
if(err != nil) {
102+
fmt.Println(err)
103+
}
104+
db := api.MySQL()
105+
doc := map[string]interface{}{"name":"SomeBook"}
106+
resp, err := db.Insert("books").Doc(doc).Apply()
107+
if err != nil {
108+
fmt.Println("Error:", err)
109+
} else {
110+
if resp.Status == 200 {
111+
fmt.Println("Success")
112+
} else {
113+
fmt.Println("Error Processing Request:", resp.Error)
114+
}
115+
}
116+
}
117+
</code>
118+
</pre>
119+
</div>
72120
</div>
73121

74122
As you would have noticed, the `insert` method is asynchronous in nature. It takes the name of the concerned collection/table. The `doc` method takes an object to be inserted. The `apply` method actually triggers the given request to `space-cloud` and returns a promise.
@@ -81,6 +129,7 @@ As you would have noticed, the `insert` method is asynchronous in nature. It tak
81129
<li class="tab col s2"><a class="active" href="#insertmany-js">Javascript</a></li>
82130
<li class="tab col s2"><a href="#insertmany-java">Java</a></li>
83131
<li class="tab col s2"><a href="#insertmany-python">Python</a></li>
132+
<li class="tab col s2"><a href="#insertmany-golang">Golang</a></li>
84133
</ul>
85134
</div>
86135
<div id="insertmany-js" class="col s12" style="padding:0">
@@ -97,7 +146,30 @@ db.insert('todos').docs(docs).apply().then(res => ...).catch(ex => ...);
97146
<div id="insertmany-java" class="col s12" style="padding:0">
98147
<pre>
99148
<code class="java">
100-
// Java client coming soon!
149+
API api = new API("books-app", "localhost", 8081);
150+
SQL db = api.MySQL();
151+
HashMap<String, String> document = new HashMap<>();
152+
document.put("name", "aBook");
153+
HashMap<String, String> document2 = new HashMap<>();
154+
document2.put("name", "anotherBook");
155+
HashMap[] docs = new HashMap[2];
156+
docs[0] = document;
157+
docs[1] = document2;
158+
db.insert("books").docs(docs).apply(new Utils.ResponseListener() {
159+
@Override
160+
public void onResponse(int statusCode, Response response) {
161+
if (statusCode == 200) {
162+
System.out.println("Success");
163+
} else {
164+
System.out.println(response.getError());
165+
}
166+
}
167+
168+
@Override
169+
public void onError(Exception e) {
170+
System.out.println(e.getMessage());
171+
}
172+
});
101173
</code>
102174
</pre>
103175
</div>
@@ -125,6 +197,37 @@ api.close()
125197
</code>
126198
</pre>
127199
</div>
200+
<div id="insertmany-golang" class="col s12" style="padding:0">
201+
<pre>
202+
<code class="golang">
203+
import (
204+
"github.com/spaceuptech/space-api-go/api"
205+
"fmt"
206+
)
207+
208+
func main() {
209+
api, err := api.Init("books-app", "localhost", "8081", false)
210+
if(err != nil) {
211+
fmt.Println(err)
212+
}
213+
db := api.MySQL()
214+
docs := make([]map[string]interface{}, 2)
215+
docs[0] = map[string]interface{}{"name": "SomeBook"}
216+
docs[1] = map[string]interface{}{"name": "SomeOtherBook"}
217+
resp, err := db.Insert("books").Docs(docs).Apply()
218+
if err != nil {
219+
fmt.Println("Error:", err)
220+
} else {
221+
if resp.Status == 200 {
222+
fmt.Println("Success")
223+
} else {
224+
fmt.Println("Error Processing Request:", resp.Error)
225+
}
226+
}
227+
}
228+
</code>
229+
</pre>
230+
</div>
128231
</div>
129232

130233
The `docs` method takes an array of objects to be inserted.

0 commit comments

Comments
 (0)