@mlagie/sql-connector 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/doc-sql-connector.html +531 -0
- package/documentation.md +159 -0
- package/index.d.ts +249 -0
- package/index.js +701 -0
- package/package.json +26 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Lagie
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,531 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<title>documentation.md</title>
|
|
5
|
+
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
|
|
6
|
+
|
|
7
|
+
<style>
|
|
8
|
+
/* https://github.com/microsoft/vscode/blob/master/extensions/markdown-language-features/media/markdown.css */
|
|
9
|
+
/*---------------------------------------------------------------------------------------------
|
|
10
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
11
|
+
* Licensed under the MIT License. See License.txt in the project root for license information.
|
|
12
|
+
*--------------------------------------------------------------------------------------------*/
|
|
13
|
+
|
|
14
|
+
body {
|
|
15
|
+
font-family: var(--vscode-markdown-font-family, -apple-system, BlinkMacSystemFont, "Segoe WPC", "Segoe UI", "Ubuntu", "Droid Sans", sans-serif);
|
|
16
|
+
font-size: var(--vscode-markdown-font-size, 14px);
|
|
17
|
+
padding: 0 26px;
|
|
18
|
+
line-height: var(--vscode-markdown-line-height, 22px);
|
|
19
|
+
word-wrap: break-word;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
#code-csp-warning {
|
|
23
|
+
position: fixed;
|
|
24
|
+
top: 0;
|
|
25
|
+
right: 0;
|
|
26
|
+
color: white;
|
|
27
|
+
margin: 16px;
|
|
28
|
+
text-align: center;
|
|
29
|
+
font-size: 12px;
|
|
30
|
+
font-family: sans-serif;
|
|
31
|
+
background-color:#444444;
|
|
32
|
+
cursor: pointer;
|
|
33
|
+
padding: 6px;
|
|
34
|
+
box-shadow: 1px 1px 1px rgba(0,0,0,.25);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
#code-csp-warning:hover {
|
|
38
|
+
text-decoration: none;
|
|
39
|
+
background-color:#007acc;
|
|
40
|
+
box-shadow: 2px 2px 2px rgba(0,0,0,.25);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
body.scrollBeyondLastLine {
|
|
44
|
+
margin-bottom: calc(100vh - 22px);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
body.showEditorSelection .code-line {
|
|
48
|
+
position: relative;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
body.showEditorSelection .code-active-line:before,
|
|
52
|
+
body.showEditorSelection .code-line:hover:before {
|
|
53
|
+
content: "";
|
|
54
|
+
display: block;
|
|
55
|
+
position: absolute;
|
|
56
|
+
top: 0;
|
|
57
|
+
left: -12px;
|
|
58
|
+
height: 100%;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
body.showEditorSelection li.code-active-line:before,
|
|
62
|
+
body.showEditorSelection li.code-line:hover:before {
|
|
63
|
+
left: -30px;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.vscode-light.showEditorSelection .code-active-line:before {
|
|
67
|
+
border-left: 3px solid rgba(0, 0, 0, 0.15);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.vscode-light.showEditorSelection .code-line:hover:before {
|
|
71
|
+
border-left: 3px solid rgba(0, 0, 0, 0.40);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.vscode-light.showEditorSelection .code-line .code-line:hover:before {
|
|
75
|
+
border-left: none;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.vscode-dark.showEditorSelection .code-active-line:before {
|
|
79
|
+
border-left: 3px solid rgba(255, 255, 255, 0.4);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.vscode-dark.showEditorSelection .code-line:hover:before {
|
|
83
|
+
border-left: 3px solid rgba(255, 255, 255, 0.60);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.vscode-dark.showEditorSelection .code-line .code-line:hover:before {
|
|
87
|
+
border-left: none;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.vscode-high-contrast.showEditorSelection .code-active-line:before {
|
|
91
|
+
border-left: 3px solid rgba(255, 160, 0, 0.7);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.vscode-high-contrast.showEditorSelection .code-line:hover:before {
|
|
95
|
+
border-left: 3px solid rgba(255, 160, 0, 1);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.vscode-high-contrast.showEditorSelection .code-line .code-line:hover:before {
|
|
99
|
+
border-left: none;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
img {
|
|
103
|
+
max-width: 100%;
|
|
104
|
+
max-height: 100%;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
a {
|
|
108
|
+
text-decoration: none;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
a:hover {
|
|
112
|
+
text-decoration: underline;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
a:focus,
|
|
116
|
+
input:focus,
|
|
117
|
+
select:focus,
|
|
118
|
+
textarea:focus {
|
|
119
|
+
outline: 1px solid -webkit-focus-ring-color;
|
|
120
|
+
outline-offset: -1px;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
hr {
|
|
124
|
+
border: 0;
|
|
125
|
+
height: 2px;
|
|
126
|
+
border-bottom: 2px solid;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
h1 {
|
|
130
|
+
padding-bottom: 0.3em;
|
|
131
|
+
line-height: 1.2;
|
|
132
|
+
border-bottom-width: 1px;
|
|
133
|
+
border-bottom-style: solid;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
h1, h2, h3 {
|
|
137
|
+
font-weight: normal;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
table {
|
|
141
|
+
border-collapse: collapse;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
table > thead > tr > th {
|
|
145
|
+
text-align: left;
|
|
146
|
+
border-bottom: 1px solid;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
table > thead > tr > th,
|
|
150
|
+
table > thead > tr > td,
|
|
151
|
+
table > tbody > tr > th,
|
|
152
|
+
table > tbody > tr > td {
|
|
153
|
+
padding: 5px 10px;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
table > tbody > tr + tr > td {
|
|
157
|
+
border-top: 1px solid;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
blockquote {
|
|
161
|
+
margin: 0 7px 0 5px;
|
|
162
|
+
padding: 0 16px 0 10px;
|
|
163
|
+
border-left-width: 5px;
|
|
164
|
+
border-left-style: solid;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
code {
|
|
168
|
+
font-family: Menlo, Monaco, Consolas, "Droid Sans Mono", "Courier New", monospace, "Droid Sans Fallback";
|
|
169
|
+
font-size: 1em;
|
|
170
|
+
line-height: 1.357em;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
body.wordWrap pre {
|
|
174
|
+
white-space: pre-wrap;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
pre:not(.hljs),
|
|
178
|
+
pre.hljs code > div {
|
|
179
|
+
padding: 16px;
|
|
180
|
+
border-radius: 3px;
|
|
181
|
+
overflow: auto;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
pre code {
|
|
185
|
+
color: var(--vscode-editor-foreground);
|
|
186
|
+
tab-size: 4;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Theming */
|
|
190
|
+
|
|
191
|
+
.vscode-light pre {
|
|
192
|
+
background-color: rgba(220, 220, 220, 0.4);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
.vscode-dark pre {
|
|
196
|
+
background-color: rgba(10, 10, 10, 0.4);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
.vscode-high-contrast pre {
|
|
200
|
+
background-color: rgb(0, 0, 0);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
.vscode-high-contrast h1 {
|
|
204
|
+
border-color: rgb(0, 0, 0);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
.vscode-light table > thead > tr > th {
|
|
208
|
+
border-color: rgba(0, 0, 0, 0.69);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
.vscode-dark table > thead > tr > th {
|
|
212
|
+
border-color: rgba(255, 255, 255, 0.69);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
.vscode-light h1,
|
|
216
|
+
.vscode-light hr,
|
|
217
|
+
.vscode-light table > tbody > tr + tr > td {
|
|
218
|
+
border-color: rgba(0, 0, 0, 0.18);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
.vscode-dark h1,
|
|
222
|
+
.vscode-dark hr,
|
|
223
|
+
.vscode-dark table > tbody > tr + tr > td {
|
|
224
|
+
border-color: rgba(255, 255, 255, 0.18);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
</style>
|
|
228
|
+
|
|
229
|
+
<style>
|
|
230
|
+
/* Tomorrow Theme */
|
|
231
|
+
/* http://jmblog.github.com/color-themes-for-google-code-highlightjs */
|
|
232
|
+
/* Original theme - https://github.com/chriskempson/tomorrow-theme */
|
|
233
|
+
|
|
234
|
+
/* Tomorrow Comment */
|
|
235
|
+
.hljs-comment,
|
|
236
|
+
.hljs-quote {
|
|
237
|
+
color: #8e908c;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/* Tomorrow Red */
|
|
241
|
+
.hljs-variable,
|
|
242
|
+
.hljs-template-variable,
|
|
243
|
+
.hljs-tag,
|
|
244
|
+
.hljs-name,
|
|
245
|
+
.hljs-selector-id,
|
|
246
|
+
.hljs-selector-class,
|
|
247
|
+
.hljs-regexp,
|
|
248
|
+
.hljs-deletion {
|
|
249
|
+
color: #c82829;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/* Tomorrow Orange */
|
|
253
|
+
.hljs-number,
|
|
254
|
+
.hljs-built_in,
|
|
255
|
+
.hljs-builtin-name,
|
|
256
|
+
.hljs-literal,
|
|
257
|
+
.hljs-type,
|
|
258
|
+
.hljs-params,
|
|
259
|
+
.hljs-meta,
|
|
260
|
+
.hljs-link {
|
|
261
|
+
color: #f5871f;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/* Tomorrow Yellow */
|
|
265
|
+
.hljs-attribute {
|
|
266
|
+
color: #eab700;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/* Tomorrow Green */
|
|
270
|
+
.hljs-string,
|
|
271
|
+
.hljs-symbol,
|
|
272
|
+
.hljs-bullet,
|
|
273
|
+
.hljs-addition {
|
|
274
|
+
color: #718c00;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/* Tomorrow Blue */
|
|
278
|
+
.hljs-title,
|
|
279
|
+
.hljs-section {
|
|
280
|
+
color: #4271ae;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/* Tomorrow Purple */
|
|
284
|
+
.hljs-keyword,
|
|
285
|
+
.hljs-selector-tag {
|
|
286
|
+
color: #8959a8;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
.hljs {
|
|
290
|
+
display: block;
|
|
291
|
+
overflow-x: auto;
|
|
292
|
+
color: #4d4d4c;
|
|
293
|
+
padding: 0.5em;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
.hljs-emphasis {
|
|
297
|
+
font-style: italic;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
.hljs-strong {
|
|
301
|
+
font-weight: bold;
|
|
302
|
+
}
|
|
303
|
+
</style>
|
|
304
|
+
|
|
305
|
+
<style>
|
|
306
|
+
/*
|
|
307
|
+
* Markdown PDF CSS
|
|
308
|
+
*/
|
|
309
|
+
|
|
310
|
+
body {
|
|
311
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe WPC", "Segoe UI", "Ubuntu", "Droid Sans", sans-serif, "Meiryo";
|
|
312
|
+
padding: 0 12px;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
pre {
|
|
316
|
+
background-color: #f8f8f8;
|
|
317
|
+
border: 1px solid #cccccc;
|
|
318
|
+
border-radius: 3px;
|
|
319
|
+
overflow-x: auto;
|
|
320
|
+
white-space: pre-wrap;
|
|
321
|
+
overflow-wrap: break-word;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
pre:not(.hljs) {
|
|
325
|
+
padding: 23px;
|
|
326
|
+
line-height: 19px;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
blockquote {
|
|
330
|
+
background: rgba(127, 127, 127, 0.1);
|
|
331
|
+
border-color: rgba(0, 122, 204, 0.5);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
.emoji {
|
|
335
|
+
height: 1.4em;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
code {
|
|
339
|
+
font-size: 14px;
|
|
340
|
+
line-height: 19px;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/* for inline code */
|
|
344
|
+
:not(pre):not(.hljs) > code {
|
|
345
|
+
color: #C9AE75; /* Change the old color so it seems less like an error */
|
|
346
|
+
font-size: inherit;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/* Page Break : use <div class="page"/> to insert page break
|
|
350
|
+
-------------------------------------------------------- */
|
|
351
|
+
.page {
|
|
352
|
+
page-break-after: always;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
</style>
|
|
356
|
+
|
|
357
|
+
<script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
|
|
358
|
+
</head>
|
|
359
|
+
<body>
|
|
360
|
+
<script>
|
|
361
|
+
mermaid.initialize({
|
|
362
|
+
startOnLoad: true,
|
|
363
|
+
theme: document.body.classList.contains('vscode-dark') || document.body.classList.contains('vscode-high-contrast')
|
|
364
|
+
? 'dark'
|
|
365
|
+
: 'default'
|
|
366
|
+
});
|
|
367
|
+
</script>
|
|
368
|
+
<h1 id="documentation-du-module-sql-connector">Documentation du module <code>sql-connector</code></h1>
|
|
369
|
+
<p>Le module <code>sql-connector</code> permet de gérer les connexions à une base de données MySQL, de définir des schémas de tables, et d'interagir avec les données de manière simple et efficace.</p>
|
|
370
|
+
<h2 id="importation-du-module">Importation du module</h2>
|
|
371
|
+
<pre class="hljs"><code><div><span class="hljs-keyword">const</span> { Schema, connect, logout, Model, client, sqlType } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'sql-connector'</span>);
|
|
372
|
+
</div></code></pre>
|
|
373
|
+
<h3 id="fonctions">Fonctions</h3>
|
|
374
|
+
<p><code>connect(config)</code> Établit une connexion à la base de données.</p>
|
|
375
|
+
<ul>
|
|
376
|
+
<li>
|
|
377
|
+
<p>Paramètres:</p>
|
|
378
|
+
<ul>
|
|
379
|
+
<li><code>config</code> (Object) : La configuration de la connexion à la base de données.</li>
|
|
380
|
+
<li><code>host</code> (string) : L'hôte de la base de données.</li>
|
|
381
|
+
<li><code>port</code> (number) : Le port de la base de données.</li>
|
|
382
|
+
<li><code>user</code> (string) : Le nom d'utilisateur pour la connexion.</li>
|
|
383
|
+
<li><code>password</code> (string) : Le mot de passe pour la connexion.</li>
|
|
384
|
+
<li><code>database</code> (string) : Le nom de la base de données.</li>
|
|
385
|
+
<li><code>ect</code> pour en savoir plus vous pouvez vous rendre sur https://github.com/mysqljs/mysql dans la section <code>Connection options</code></li>
|
|
386
|
+
</ul>
|
|
387
|
+
</li>
|
|
388
|
+
<li>
|
|
389
|
+
<h3 id="exemple">Exemple:</h3>
|
|
390
|
+
</li>
|
|
391
|
+
</ul>
|
|
392
|
+
<pre class="hljs"><code><div><span class="hljs-keyword">const</span> config = {
|
|
393
|
+
<span class="hljs-attr">host</span>: <span class="hljs-string">'localhost'</span>,
|
|
394
|
+
<span class="hljs-attr">port</span>: <span class="hljs-number">3306</span>,
|
|
395
|
+
<span class="hljs-attr">user</span>: <span class="hljs-string">'root'</span>,
|
|
396
|
+
<span class="hljs-attr">password</span>: <span class="hljs-string">'password'</span>,
|
|
397
|
+
<span class="hljs-attr">database</span>: <span class="hljs-string">'mydatabase'</span>
|
|
398
|
+
};
|
|
399
|
+
<span class="hljs-keyword">await</span> connect(config);
|
|
400
|
+
</div></code></pre>
|
|
401
|
+
<p><code>logout()</code> Ferme la connexion à la base de données.</p>
|
|
402
|
+
<ul>
|
|
403
|
+
<li>
|
|
404
|
+
<h3 id="exemple">Exemple:</h3>
|
|
405
|
+
</li>
|
|
406
|
+
</ul>
|
|
407
|
+
<pre class="hljs"><code><div><span class="hljs-keyword">await</span> logout();
|
|
408
|
+
</div></code></pre>
|
|
409
|
+
<h3 id="classes-schema">Classes <code>Schema</code></h3>
|
|
410
|
+
<p>Représente un schéma de base de données.</p>
|
|
411
|
+
<ul>
|
|
412
|
+
<li>
|
|
413
|
+
<p>Constructeur:</p>
|
|
414
|
+
<ul>
|
|
415
|
+
<li>Schema(schemaDict) : Crée une instance de Schema.
|
|
416
|
+
<ul>
|
|
417
|
+
<li>schemaDict (Object) : Un dictionnaire définissant le schéma.</li>
|
|
418
|
+
</ul>
|
|
419
|
+
</li>
|
|
420
|
+
</ul>
|
|
421
|
+
</li>
|
|
422
|
+
<li>
|
|
423
|
+
<p>Exemple</p>
|
|
424
|
+
</li>
|
|
425
|
+
</ul>
|
|
426
|
+
<pre class="hljs"><code><div><span class="hljs-keyword">const</span> transferSchema = <span class="hljs-keyword">new</span> Schema({
|
|
427
|
+
<span class="hljs-attr">token</span>: {
|
|
428
|
+
<span class="hljs-attr">type</span>: <span class="hljs-built_in">String</span>,
|
|
429
|
+
<span class="hljs-attr">length</span>: <span class="hljs-number">50</span>
|
|
430
|
+
},
|
|
431
|
+
<span class="hljs-attr">mdp</span>: {
|
|
432
|
+
<span class="hljs-attr">type</span>: <span class="hljs-built_in">String</span>,
|
|
433
|
+
<span class="hljs-attr">length</span>: <span class="hljs-number">15</span>
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
</div></code></pre>
|
|
437
|
+
<h2 id="class-model">Class Model</h2>
|
|
438
|
+
<p>Représente un modèle de base de données.</p>
|
|
439
|
+
<ul>
|
|
440
|
+
<li>
|
|
441
|
+
<h3 id="constructeur">Constructeur :</h3>
|
|
442
|
+
<ul>
|
|
443
|
+
<li><code>Model(name, schema)</code> : Crée une instance de <code>Model</code>.</li>
|
|
444
|
+
<li><code>name (string)</code> : Le nom de la table de base de données.</li>
|
|
445
|
+
<li><code>schema (Schema)</code> : Le schéma de la table de base de données.</li>
|
|
446
|
+
</ul>
|
|
447
|
+
</li>
|
|
448
|
+
<li>
|
|
449
|
+
<h3 id="m%C3%A9thodes">Méthodes :</h3>
|
|
450
|
+
<ul>
|
|
451
|
+
<li><code>generateCreateTableStatement(schema)</code> : Génère une requête SQL pour créer une table.</li>
|
|
452
|
+
<li><code>save(data)</code> : Sauvegarde des données dans la table.</li>
|
|
453
|
+
<li><code>findOne(filter, fields)</code> : Trouve une entrée unique dans la table.</li>
|
|
454
|
+
<li><code>find(filter, fields)</code> : Trouve des entrées dans la table.</li>
|
|
455
|
+
<li><code>customRequest(custom)</code> : Exécute une requête SQL personnalisée.</li>
|
|
456
|
+
<li><code>delete(filter)</code> : Supprime une entrée de la table.</li>
|
|
457
|
+
<li><code>dropTable()</code> : Supprime la table si elle existe.</li>
|
|
458
|
+
<li><code>generate_uuid()</code> : Génère un UUID unique pour le modèle.</li>
|
|
459
|
+
</ul>
|
|
460
|
+
</li>
|
|
461
|
+
<li>
|
|
462
|
+
<h3 id="exemple">Exemple</h3>
|
|
463
|
+
</li>
|
|
464
|
+
</ul>
|
|
465
|
+
<pre class="hljs"><code><div><span class="hljs-keyword">const</span> userModel = <span class="hljs-keyword">new</span> Model(<span class="hljs-string">'users'</span>, transferSchema);
|
|
466
|
+
|
|
467
|
+
<span class="hljs-comment">// Sauvegarder des données</span>
|
|
468
|
+
<span class="hljs-keyword">await</span> userModel.save({ <span class="hljs-attr">token</span>: <span class="hljs-string">'abc123'</span>, <span class="hljs-attr">mdp</span>: <span class="hljs-string">'password'</span> });
|
|
469
|
+
|
|
470
|
+
<span class="hljs-comment">// Trouver une entrée</span>
|
|
471
|
+
<span class="hljs-keyword">const</span> user = <span class="hljs-keyword">await</span> userModel.findOne({ <span class="hljs-attr">token</span>: <span class="hljs-string">'abc123'</span> });
|
|
472
|
+
|
|
473
|
+
<span class="hljs-comment">// Supprimer une entrée</span>
|
|
474
|
+
<span class="hljs-keyword">await</span> userModel.delete({ <span class="hljs-attr">token</span>: <span class="hljs-string">'abc123'</span> });
|
|
475
|
+
</div></code></pre>
|
|
476
|
+
<h2 id="class-modelinstance">Class ModelInstance</h2>
|
|
477
|
+
<p>Représente une instance d'un modèle de base de données.</p>
|
|
478
|
+
<ul>
|
|
479
|
+
<li>
|
|
480
|
+
<h3 id="constructeur">Constructeur:</h3>
|
|
481
|
+
<ul>
|
|
482
|
+
<li><code>ModelInstance(name, data)</code> : Crée une instance de <code>ModelInstance</code>.</li>
|
|
483
|
+
<li><code>name (string)</code> : Le nom de la table de base de données.</li>
|
|
484
|
+
<li><code>data (Object)</code> : Les données de l'instance.</li>
|
|
485
|
+
</ul>
|
|
486
|
+
</li>
|
|
487
|
+
<li>
|
|
488
|
+
<h3 id="m%C3%A9thodes">Méthodes :</h3>
|
|
489
|
+
<ul>
|
|
490
|
+
<li><code>updateOne(model)</code> : Met à jour une entrée unique dans la table.</li>
|
|
491
|
+
<li><code>delete(model)</code> : Supprime une entrée unique dans la table.</li>
|
|
492
|
+
<li><code>customRequest(custom)</code> : Exécute une requête SQL personnalisée.</li>
|
|
493
|
+
</ul>
|
|
494
|
+
</li>
|
|
495
|
+
<li>
|
|
496
|
+
<h3 id="exemple">Exemple</h3>
|
|
497
|
+
</li>
|
|
498
|
+
</ul>
|
|
499
|
+
<pre class="hljs"><code><div><span class="hljs-keyword">const</span> userInstance = <span class="hljs-keyword">new</span> ModelInstance(<span class="hljs-string">'users'</span>, { <span class="hljs-attr">token</span>: <span class="hljs-string">'abc123'</span>, <span class="hljs-attr">mdp</span>: <span class="hljs-string">'password'</span> });
|
|
500
|
+
|
|
501
|
+
<span class="hljs-comment">// Mettre à jour des données</span>
|
|
502
|
+
<span class="hljs-keyword">await</span> userInstance.updateOne({ <span class="hljs-attr">mdp</span>: <span class="hljs-string">'newpassword'</span> });
|
|
503
|
+
|
|
504
|
+
<span class="hljs-comment">// Supprimer des données</span>
|
|
505
|
+
<span class="hljs-keyword">await</span> userInstance.delete({ <span class="hljs-attr">token</span>: <span class="hljs-string">'abc123'</span> });
|
|
506
|
+
</div></code></pre>
|
|
507
|
+
<h1 id="types-sql">Types SQL</h1>
|
|
508
|
+
<p>Le module fournit également une map des types SQL courants via <code>sqlType</code>.</p>
|
|
509
|
+
<h2 id="type">Type</h2>
|
|
510
|
+
<ul>
|
|
511
|
+
<li>String</li>
|
|
512
|
+
<li>Number</li>
|
|
513
|
+
<li>Boolean</li>
|
|
514
|
+
<li>Object</li>
|
|
515
|
+
<li>Array</li>
|
|
516
|
+
<li>Now</li>
|
|
517
|
+
<li>Float</li>
|
|
518
|
+
<li>Text</li>
|
|
519
|
+
<li>DateTime</li>
|
|
520
|
+
<li>
|
|
521
|
+
<h3 id="exemple">Exemple</h3>
|
|
522
|
+
</li>
|
|
523
|
+
</ul>
|
|
524
|
+
<pre class="hljs"><code><div><span class="hljs-built_in">console</span>.log(sqlType.String); <span class="hljs-comment">// "String"</span>
|
|
525
|
+
<span class="hljs-built_in">console</span>.log(sqlTypeMap.String); <span class="hljs-comment">// "VARCHAR"</span>
|
|
526
|
+
</div></code></pre>
|
|
527
|
+
<h2 id="conclusion">Conclusion</h2>
|
|
528
|
+
<p>Le module <code>sql-connector</code> fournit une interface simple et efficace pour interagir avec une base de données MySQL, permettant de définir des schémas, de gérer des connexions, et de manipuler des données de manière intuitive.</p>
|
|
529
|
+
|
|
530
|
+
</body>
|
|
531
|
+
</html>
|