@@ -8,6 +8,7 @@ You can add data to your app by simply calling `db.insert` on the frontend. Here
8
8
<li class="tab col s2"><a class="active" href="#insert-js">Javascript</a></li>
9
9
<li class="tab col s2"><a href="#insert-java">Java</a></li>
10
10
<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>
11
12
</ul>
12
13
</div >
13
14
<div id =" insert-js " class =" col s12 " style =" padding :0 " >
@@ -41,7 +42,25 @@ db.insert("todos").doc(doc).apply()
41
42
<div id =" insert-java " class =" col s12 " style =" padding :0 " >
42
43
<pre>
43
44
<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
+ });
45
64
</code >
46
65
</pre >
47
66
</div >
@@ -69,6 +88,35 @@ api.close()
69
88
</code >
70
89
</pre >
71
90
</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 >
72
120
</div >
73
121
74
122
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
81
129
<li class="tab col s2"><a class="active" href="#insertmany-js">Javascript</a></li>
82
130
<li class="tab col s2"><a href="#insertmany-java">Java</a></li>
83
131
<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>
84
133
</ul>
85
134
</div >
86
135
<div id =" insertmany-js " class =" col s12 " style =" padding :0 " >
@@ -97,7 +146,30 @@ db.insert('todos').docs(docs).apply().then(res => ...).catch(ex => ...);
97
146
<div id =" insertmany-java " class =" col s12 " style =" padding :0 " >
98
147
<pre>
99
148
<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
+ });
101
173
</code >
102
174
</pre >
103
175
</div >
@@ -125,6 +197,37 @@ api.close()
125
197
</code >
126
198
</pre >
127
199
</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 >
128
231
</div >
129
232
130
233
The ` docs ` method takes an array of objects to be inserted.
0 commit comments