@mostajs/orm 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.
Files changed (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +548 -0
  3. package/dist/core/base-repository.d.ts +26 -0
  4. package/dist/core/base-repository.js +82 -0
  5. package/dist/core/config.d.ts +62 -0
  6. package/dist/core/config.js +116 -0
  7. package/dist/core/errors.d.ts +30 -0
  8. package/dist/core/errors.js +49 -0
  9. package/dist/core/factory.d.ts +41 -0
  10. package/dist/core/factory.js +142 -0
  11. package/dist/core/normalizer.d.ts +9 -0
  12. package/dist/core/normalizer.js +19 -0
  13. package/dist/core/registry.d.ts +43 -0
  14. package/dist/core/registry.js +78 -0
  15. package/dist/core/types.d.ts +228 -0
  16. package/dist/core/types.js +5 -0
  17. package/dist/dialects/abstract-sql.dialect.d.ts +113 -0
  18. package/dist/dialects/abstract-sql.dialect.js +1071 -0
  19. package/dist/dialects/cockroachdb.dialect.d.ts +2 -0
  20. package/dist/dialects/cockroachdb.dialect.js +23 -0
  21. package/dist/dialects/db2.dialect.d.ts +2 -0
  22. package/dist/dialects/db2.dialect.js +190 -0
  23. package/dist/dialects/hana.dialect.d.ts +2 -0
  24. package/dist/dialects/hana.dialect.js +199 -0
  25. package/dist/dialects/hsqldb.dialect.d.ts +2 -0
  26. package/dist/dialects/hsqldb.dialect.js +114 -0
  27. package/dist/dialects/mariadb.dialect.d.ts +2 -0
  28. package/dist/dialects/mariadb.dialect.js +87 -0
  29. package/dist/dialects/mongo.dialect.d.ts +2 -0
  30. package/dist/dialects/mongo.dialect.js +480 -0
  31. package/dist/dialects/mssql.dialect.d.ts +27 -0
  32. package/dist/dialects/mssql.dialect.js +127 -0
  33. package/dist/dialects/mysql.dialect.d.ts +24 -0
  34. package/dist/dialects/mysql.dialect.js +101 -0
  35. package/dist/dialects/oracle.dialect.d.ts +2 -0
  36. package/dist/dialects/oracle.dialect.js +206 -0
  37. package/dist/dialects/postgres.dialect.d.ts +26 -0
  38. package/dist/dialects/postgres.dialect.js +105 -0
  39. package/dist/dialects/spanner.dialect.d.ts +2 -0
  40. package/dist/dialects/spanner.dialect.js +259 -0
  41. package/dist/dialects/sqlite.dialect.d.ts +2 -0
  42. package/dist/dialects/sqlite.dialect.js +1027 -0
  43. package/dist/dialects/sybase.dialect.d.ts +2 -0
  44. package/dist/dialects/sybase.dialect.js +119 -0
  45. package/dist/index.d.ts +8 -0
  46. package/dist/index.js +26 -0
  47. package/docs/api-reference.md +1009 -0
  48. package/docs/dialects.md +673 -0
  49. package/docs/tutorial.md +846 -0
  50. package/package.json +91 -0
@@ -0,0 +1,673 @@
1
+ # MostaORM — Guide des dialectes
2
+
3
+ > Configuration détaillée de chacun des 13 dialectes supportés.
4
+
5
+ ---
6
+
7
+ ## Table des matières
8
+
9
+ 1. [SQLite](#1-sqlite)
10
+ 2. [PostgreSQL](#2-postgresql)
11
+ 3. [MySQL](#3-mysql)
12
+ 4. [MariaDB](#4-mariadb)
13
+ 5. [MongoDB](#5-mongodb)
14
+ 6. [Microsoft SQL Server (MSSQL)](#6-microsoft-sql-server-mssql)
15
+ 7. [Oracle Database](#7-oracle-database)
16
+ 8. [CockroachDB](#8-cockroachdb)
17
+ 9. [IBM DB2](#9-ibm-db2)
18
+ 10. [SAP HANA](#10-sap-hana)
19
+ 11. [HyperSQL (HSQLDB)](#11-hypersql-hsqldb)
20
+ 12. [Google Cloud Spanner](#12-google-cloud-spanner)
21
+ 13. [Sybase / SAP ASE](#13-sybase--sap-ase)
22
+ 14. [Variables d'environnement communes](#14-variables-denvironnement-communes)
23
+ 15. [Comparaison des fonctionnalités](#15-comparaison-des-fonctionnalités)
24
+
25
+ ---
26
+
27
+ ## 1. SQLite
28
+
29
+ **Driver** : `better-sqlite3`
30
+ **Idéal pour** : applications embarquées, développement, tests, Electron, CLI tools
31
+
32
+ ### Installation
33
+
34
+ ```bash
35
+ npm install better-sqlite3
36
+ npm install @types/better-sqlite3 --save-dev
37
+ ```
38
+
39
+ ### Configuration
40
+
41
+ ```typescript
42
+ import { createConnection } from '@mosta/orm'
43
+
44
+ const dialect = await createConnection({
45
+ dialect: 'sqlite',
46
+ uri: './data/myapp.db', // chemin relatif ou absolu
47
+ schemaStrategy: 'update',
48
+ })
49
+ ```
50
+
51
+ ### URIs SQLite
52
+
53
+ ```env
54
+ # Fichier local
55
+ SGBD_URI=./data/myapp.db
56
+ SGBD_URI=/absolute/path/to/db.sqlite
57
+
58
+ # Base de données en mémoire (tests)
59
+ SGBD_URI=:memory:
60
+ ```
61
+
62
+ ### Notes importantes
63
+
64
+ - Pas de serveur requis — le fichier `.db` est la base de données
65
+ - Les tableaux (`array`) et JSON sont stockés sous forme de texte sérialisé
66
+ - La recherche full-text utilise `LIKE %query%` (pas d'index FTS par défaut)
67
+ - Excellent pour les tests unitaires avec `schemaStrategy: 'create-drop'`
68
+ - Thread-safe en lecture seule ; en écriture, les accès sont sérialisés automatiquement
69
+
70
+ ### Exemple complet
71
+
72
+ ```env
73
+ DB_DIALECT=sqlite
74
+ SGBD_URI=./data/dev.db
75
+ DB_SCHEMA_STRATEGY=update
76
+ DB_SHOW_SQL=true
77
+ ```
78
+
79
+ ---
80
+
81
+ ## 2. PostgreSQL
82
+
83
+ **Driver** : `pg`
84
+ **Idéal pour** : applications web de production, données géographiques (PostGIS), full-text search avancé
85
+
86
+ ### Installation
87
+
88
+ ```bash
89
+ npm install pg
90
+ npm install @types/pg --save-dev
91
+ ```
92
+
93
+ ### Configuration
94
+
95
+ ```typescript
96
+ const dialect = await createConnection({
97
+ dialect: 'postgres',
98
+ uri: 'postgresql://user:password@localhost:5432/mydb',
99
+ schemaStrategy: 'update',
100
+ poolSize: 10,
101
+ showSql: false,
102
+ })
103
+ ```
104
+
105
+ ### Formats d'URI PostgreSQL
106
+
107
+ ```env
108
+ # Format standard
109
+ SGBD_URI=postgresql://user:password@localhost:5432/mydb
110
+
111
+ # Avec SSL
112
+ SGBD_URI=postgresql://user:password@host:5432/mydb?sslmode=require
113
+
114
+ # Supabase
115
+ SGBD_URI=postgresql://postgres:password@db.xxxxx.supabase.co:5432/postgres
116
+
117
+ # Neon (serverless)
118
+ SGBD_URI=postgresql://user:password@ep-xxx.us-east-2.aws.neon.tech/mydb?sslmode=require
119
+
120
+ # Railway
121
+ SGBD_URI=postgresql://postgres:password@containers-us-west.railway.app:5432/railway
122
+
123
+ # URL encodé (avec caractères spéciaux dans le mot de passe)
124
+ SGBD_URI=postgresql://user:p%40ssword@localhost:5432/mydb
125
+ ```
126
+
127
+ ### Variables d'environnement
128
+
129
+ ```env
130
+ DB_DIALECT=postgres
131
+ SGBD_URI=postgresql://user:pass@localhost:5432/mydb
132
+ DB_SCHEMA_STRATEGY=validate
133
+ DB_POOL_SIZE=10
134
+ DB_SHOW_SQL=false
135
+ DB_CACHE_ENABLED=true
136
+ DB_CACHE_TTL=120
137
+ ```
138
+
139
+ ### Notes importantes
140
+
141
+ - Les champs `json` utilisent `JSONB` pour des performances optimales
142
+ - Les index `text` utilisent `to_tsvector` pour la recherche full-text
143
+ - Compatible avec PgBouncer (connection pooling)
144
+ - SSL recommandé en production (`?sslmode=require`)
145
+
146
+ ---
147
+
148
+ ## 3. MySQL
149
+
150
+ **Driver** : `mysql2`
151
+ **Idéal pour** : applications web traditionnelles, grande communauté, hébergements mutualisés
152
+
153
+ ### Installation
154
+
155
+ ```bash
156
+ npm install mysql2
157
+ ```
158
+
159
+ ### Configuration
160
+
161
+ ```typescript
162
+ const dialect = await createConnection({
163
+ dialect: 'mysql',
164
+ uri: 'mysql://user:password@localhost:3306/mydb',
165
+ schemaStrategy: 'update',
166
+ poolSize: 5,
167
+ })
168
+ ```
169
+
170
+ ### Formats d'URI MySQL
171
+
172
+ ```env
173
+ # Format standard
174
+ SGBD_URI=mysql://user:password@localhost:3306/mydb
175
+
176
+ # Avec charset
177
+ SGBD_URI=mysql://user:password@localhost:3306/mydb?charset=utf8mb4
178
+
179
+ # PlanetScale
180
+ SGBD_URI=mysql://user:password@aws.connect.psdb.cloud/mydb?ssl={"rejectUnauthorized":true}
181
+
182
+ # Amazon RDS MySQL
183
+ SGBD_URI=mysql://admin:password@mydb.cluster.us-east-1.rds.amazonaws.com:3306/mydb
184
+ ```
185
+
186
+ ### Variables d'environnement
187
+
188
+ ```env
189
+ DB_DIALECT=mysql
190
+ SGBD_URI=mysql://root:rootpass@localhost:3306/myapp
191
+ DB_SCHEMA_STRATEGY=update
192
+ DB_POOL_SIZE=5
193
+ ```
194
+
195
+ ### Notes importantes
196
+
197
+ - Utilisez `utf8mb4` comme charset pour le support complet Unicode (emojis inclus)
198
+ - Les champs `json` utilisent le type `JSON` de MySQL 5.7+
199
+ - MySQL 8.0+ recommandé pour les meilleures performances
200
+
201
+ ---
202
+
203
+ ## 4. MariaDB
204
+
205
+ **Driver** : `mariadb`
206
+ **Idéal pour** : compatible MySQL avec fonctionnalités étendues, open source à 100%
207
+
208
+ ### Installation
209
+
210
+ ```bash
211
+ npm install mariadb
212
+ ```
213
+
214
+ ### Configuration
215
+
216
+ ```typescript
217
+ const dialect = await createConnection({
218
+ dialect: 'mariadb',
219
+ uri: 'mariadb://user:password@localhost:3306/mydb',
220
+ schemaStrategy: 'update',
221
+ })
222
+ ```
223
+
224
+ ### Formats d'URI MariaDB
225
+
226
+ ```env
227
+ SGBD_URI=mariadb://user:password@localhost:3306/mydb
228
+ SGBD_URI=mariadb://user:password@mariadb.host.com:3306/mydb?ssl=true
229
+ ```
230
+
231
+ ### Notes importantes
232
+
233
+ - Syntaxe SQL identique à MySQL — les schémas sont entièrement compatibles
234
+ - Légèrement plus rapide que MySQL pour les opérations d'écriture
235
+ - Meilleur support des clauses `RETURNING` (MariaDB 10.5+)
236
+
237
+ ---
238
+
239
+ ## 5. MongoDB
240
+
241
+ **Driver** : `mongoose`
242
+ **Idéal pour** : données semi-structurées, documents imbriqués, scalabilité horizontale
243
+
244
+ ### Installation
245
+
246
+ ```bash
247
+ npm install mongoose
248
+ ```
249
+
250
+ ### Configuration
251
+
252
+ ```typescript
253
+ const dialect = await createConnection({
254
+ dialect: 'mongodb',
255
+ uri: 'mongodb://localhost:27017/mydb',
256
+ schemaStrategy: 'update', // crée les collections et index automatiquement
257
+ })
258
+ ```
259
+
260
+ ### Formats d'URI MongoDB
261
+
262
+ ```env
263
+ # Local sans authentification
264
+ SGBD_URI=mongodb://localhost:27017/mydb
265
+
266
+ # Local avec authentification
267
+ SGBD_URI=mongodb://user:password@localhost:27017/mydb?authSource=admin
268
+
269
+ # MongoDB Atlas (cloud)
270
+ SGBD_URI=mongodb+srv://user:password@cluster0.xxxxx.mongodb.net/mydb
271
+
272
+ # Replica Set
273
+ SGBD_URI=mongodb://host1:27017,host2:27017,host3:27017/mydb?replicaSet=rs0
274
+
275
+ # MongoDB Atlas avec options TLS
276
+ SGBD_URI=mongodb+srv://user:pass@cluster.mongodb.net/db?retryWrites=true&w=majority
277
+ ```
278
+
279
+ ### Variables d'environnement
280
+
281
+ ```env
282
+ DB_DIALECT=mongodb
283
+ SGBD_URI=mongodb://devuser:devpass@localhost:27017/myappdb
284
+ DB_SCHEMA_STRATEGY=update
285
+ DB_SHOW_SQL=false
286
+ ```
287
+
288
+ ### Notes importantes
289
+
290
+ - Les `relations` utilisent `populate()` de Mongoose (références par ObjectId)
291
+ - Les `indexes` sont créés comme index MongoDB
292
+ - Les champs `array` et `json` sont natifs — pas de sérialisation
293
+ - `schemaStrategy: 'create'` supprime et recrée toutes les collections
294
+
295
+ ---
296
+
297
+ ## 6. Microsoft SQL Server (MSSQL)
298
+
299
+ **Driver** : `mssql`
300
+ **Idéal pour** : environnements Microsoft, Azure SQL, intégration .NET
301
+
302
+ ### Installation
303
+
304
+ ```bash
305
+ npm install mssql
306
+ ```
307
+
308
+ ### Configuration
309
+
310
+ ```typescript
311
+ const dialect = await createConnection({
312
+ dialect: 'mssql',
313
+ uri: 'mssql://sa:Password123!@localhost:1433/mydb',
314
+ schemaStrategy: 'update',
315
+ })
316
+ ```
317
+
318
+ ### Formats d'URI MSSQL
319
+
320
+ ```env
321
+ # Authentification SQL Server
322
+ SGBD_URI=mssql://username:password@localhost:1433/mydb
323
+
324
+ # Azure SQL Database
325
+ SGBD_URI=mssql://user@server:password@server.database.windows.net:1433/mydb?encrypt=true
326
+
327
+ # SQL Server Express (instance nommée)
328
+ SGBD_URI=mssql://sa:pass@localhost\\SQLEXPRESS:1433/mydb
329
+
330
+ # Avec options SSL
331
+ SGBD_URI=mssql://user:pass@host:1433/mydb?encrypt=true&trustServerCertificate=true
332
+ ```
333
+
334
+ ### Notes importantes
335
+
336
+ - SQL Server 2017+ ou Azure SQL Database requis
337
+ - Les champs `boolean` sont stockés comme `BIT`
338
+ - Les champs `json` sont stockés comme `NVARCHAR(MAX)`
339
+ - L'authentification Windows (`trusted_connection=true`) nécessite des options supplémentaires
340
+
341
+ ---
342
+
343
+ ## 7. Oracle Database
344
+
345
+ **Driver** : `oracledb`
346
+ **Idéal pour** : entreprises Oracle, Oracle Cloud, compatibilité legacy
347
+
348
+ ### Installation
349
+
350
+ ```bash
351
+ npm install oracledb
352
+ ```
353
+
354
+ > Oracle Instant Client requis — voir la [documentation officielle oracledb](https://node-oracledb.readthedocs.io/en/latest/user_guide/installation.html).
355
+
356
+ ### Configuration
357
+
358
+ ```typescript
359
+ const dialect = await createConnection({
360
+ dialect: 'oracle',
361
+ uri: 'oracle://user:password@localhost:1521/ORCL',
362
+ schemaStrategy: 'update',
363
+ })
364
+ ```
365
+
366
+ ### Formats d'URI Oracle
367
+
368
+ ```env
369
+ # Service name
370
+ SGBD_URI=oracle://user:password@localhost:1521/XEPDB1
371
+
372
+ # SID (ancien format)
373
+ SGBD_URI=oracle://user:password@localhost:1521:ORCL
374
+
375
+ # Oracle Cloud (TNS)
376
+ SGBD_URI=oracle://user:password@tcps://adb.region.oraclecloud.com:1522/service_name
377
+ ```
378
+
379
+ ### Notes importantes
380
+
381
+ - Oracle Database 12c+ recommandé
382
+ - Les noms de tables sont convertis en UPPERCASE (convention Oracle)
383
+ - Les colonnes `CLOB` sont utilisées pour les champs `json` et `array`
384
+ - Nécessite Oracle Instant Client (bibliothèques C partagées)
385
+
386
+ ---
387
+
388
+ ## 8. CockroachDB
389
+
390
+ **Driver** : `pg` (protocole PostgreSQL compatible)
391
+ **Idéal pour** : scalabilité horizontale, résistance aux pannes, multi-région
392
+
393
+ ### Installation
394
+
395
+ ```bash
396
+ npm install pg
397
+ npm install @types/pg --save-dev
398
+ ```
399
+
400
+ ### Configuration
401
+
402
+ ```typescript
403
+ const dialect = await createConnection({
404
+ dialect: 'cockroachdb',
405
+ uri: 'postgresql://root@localhost:26257/defaultdb?sslmode=disable',
406
+ schemaStrategy: 'update',
407
+ })
408
+ ```
409
+
410
+ ### Formats d'URI CockroachDB
411
+
412
+ ```env
413
+ # Local (développement, sans SSL)
414
+ SGBD_URI=postgresql://root@localhost:26257/defaultdb?sslmode=disable
415
+
416
+ # CockroachDB Cloud (Serverless)
417
+ SGBD_URI=postgresql://user:password@free-tier.gcp-us-central1.cockroachlabs.cloud:26257/mydb?sslmode=verify-full&sslrootcert=/path/to/ca.crt
418
+
419
+ # CockroachDB Dedicated
420
+ SGBD_URI=postgresql://user:password@cluster.region.cockroachlabs.cloud:26257/mydb?sslmode=require
421
+ ```
422
+
423
+ ### Notes importantes
424
+
425
+ - Syntaxe SQL très proche de PostgreSQL — haute compatibilité
426
+ - Transactions distribuées ACID par défaut
427
+ - `SERIAL` → `UUID` recommandé pour les IDs distribués
428
+ - La stratégie `schemaStrategy: 'update'` est sans risque (ALTER TABLE)
429
+
430
+ ---
431
+
432
+ ## 9. IBM DB2
433
+
434
+ **Driver** : `ibm_db`
435
+ **Idéal pour** : environnements IBM mainframe, IBM Cloud
436
+
437
+ ### Installation
438
+
439
+ ```bash
440
+ npm install ibm_db
441
+ ```
442
+
443
+ ### Configuration
444
+
445
+ ```typescript
446
+ const dialect = await createConnection({
447
+ dialect: 'db2',
448
+ uri: 'db2://user:password@localhost:50000/SAMPLE',
449
+ schemaStrategy: 'update',
450
+ })
451
+ ```
452
+
453
+ ### Formats d'URI DB2
454
+
455
+ ```env
456
+ # Local
457
+ SGBD_URI=db2://user:password@localhost:50000/SAMPLE
458
+
459
+ # IBM Cloud Db2
460
+ SGBD_URI=db2://user:password@dashdb-txn-sbox-yp-xxx.services.dal.bluemix.net:50000/BLUDB:SECURITY=SSL;
461
+ ```
462
+
463
+ ### Notes importantes
464
+
465
+ - DB2 for LUW (Linux, Unix, Windows) — pas DB2 for z/OS
466
+ - Les noms de schéma sont en UPPERCASE par convention
467
+ - `ibm_db` nécessite le client CLI IBM Data Server (bibliothèques C natives)
468
+
469
+ ---
470
+
471
+ ## 10. SAP HANA
472
+
473
+ **Driver** : `@sap/hana-client`
474
+ **Idéal pour** : analytics temps réel, SAP ecosystem, in-memory computing
475
+
476
+ ### Installation
477
+
478
+ ```bash
479
+ npm install @sap/hana-client
480
+ ```
481
+
482
+ ### Configuration
483
+
484
+ ```typescript
485
+ const dialect = await createConnection({
486
+ dialect: 'hana',
487
+ uri: 'hana://user:password@host:39013/myschema',
488
+ schemaStrategy: 'update',
489
+ })
490
+ ```
491
+
492
+ ### Formats d'URI HANA
493
+
494
+ ```env
495
+ # HANA on-premises
496
+ SGBD_URI=hana://user:password@hanahost:39013
497
+
498
+ # SAP HANA Cloud
499
+ SGBD_URI=hana://user:password@xxx.hanacloud.ondemand.com:443?encrypt=true&sslValidateCertificate=false
500
+
501
+ # Avec schéma par défaut
502
+ SGBD_URI=hana://user:password@host:39013?currentSchema=MYSCHEMA
503
+ ```
504
+
505
+ ### Notes importantes
506
+
507
+ - HANA utilise des schémas (namespaces) — définissez `currentSchema` dans l'URI
508
+ - Colonnes en UPPERCASE par défaut
509
+ - Performances analytiques exceptionnelles sur les agrégations
510
+ - `@sap/hana-client` disponible sur npm.sap.com
511
+
512
+ ---
513
+
514
+ ## 11. HyperSQL (HSQLDB)
515
+
516
+ **Driver** : Java via JDBC (pont JavaScript)
517
+ **Idéal pour** : tests embarqués, compatibilité Java, bases de données in-memory
518
+
519
+ ### Notes
520
+
521
+ HSQLDB est une base de données Java. L'adaptateur MostaORM utilise un pont JDBC-to-Node. Pour la plupart des cas d'usage embarqués, préférez SQLite qui ne nécessite pas de JVM.
522
+
523
+ ```typescript
524
+ const dialect = await createConnection({
525
+ dialect: 'hsqldb',
526
+ uri: 'hsqldb:mem:testdb',
527
+ schemaStrategy: 'create-drop',
528
+ })
529
+ ```
530
+
531
+ ---
532
+
533
+ ## 12. Google Cloud Spanner
534
+
535
+ **Driver** : `@google-cloud/spanner`
536
+ **Idéal pour** : scalabilité mondiale, transactions distribuées à l'échelle globale
537
+
538
+ ### Installation
539
+
540
+ ```bash
541
+ npm install @google-cloud/spanner
542
+ ```
543
+
544
+ ### Configuration
545
+
546
+ ```typescript
547
+ const dialect = await createConnection({
548
+ dialect: 'spanner',
549
+ uri: 'spanner://projects/my-project/instances/my-instance/databases/my-database',
550
+ schemaStrategy: 'update',
551
+ options: {
552
+ credentials: {
553
+ client_email: '...',
554
+ private_key: '...',
555
+ }
556
+ }
557
+ })
558
+ ```
559
+
560
+ ### Authentification
561
+
562
+ ```bash
563
+ # Via fichier de compte de service
564
+ export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json
565
+
566
+ # Via gcloud CLI
567
+ gcloud auth application-default login
568
+ ```
569
+
570
+ ### Formats d'URI Spanner
571
+
572
+ ```env
573
+ SGBD_URI=spanner://projects/my-gcp-project/instances/my-instance/databases/mydb
574
+ ```
575
+
576
+ ### Notes importantes
577
+
578
+ - Nécessite un compte GCP avec l'API Spanner activée
579
+ - Facturation à l'usage — voir tarifs Google Cloud
580
+ - Excellent pour les applications nécessitant une cohérence globale forte
581
+ - Interleaved tables pour les relations parent-enfant (performance)
582
+
583
+ ---
584
+
585
+ ## 13. Sybase / SAP ASE
586
+
587
+ **Driver** : `mssql` (protocole compatible TDS)
588
+ **Idéal pour** : migration depuis Sybase, environnements SAP ASE legacy
589
+
590
+ ### Installation
591
+
592
+ ```bash
593
+ npm install mssql
594
+ ```
595
+
596
+ ### Configuration
597
+
598
+ ```typescript
599
+ const dialect = await createConnection({
600
+ dialect: 'sybase',
601
+ uri: 'sybase://user:password@localhost:5000/mydb',
602
+ schemaStrategy: 'update',
603
+ })
604
+ ```
605
+
606
+ ### Notes importantes
607
+
608
+ - Utilise le protocole TDS (compatible avec le driver `mssql`)
609
+ - SAP ASE (Adaptive Server Enterprise) — anciennement Sybase ASE
610
+ - SQL proche de T-SQL (Microsoft SQL Server)
611
+
612
+ ---
613
+
614
+ ## 14. Variables d'environnement communes
615
+
616
+ Ces variables s'appliquent à tous les dialectes :
617
+
618
+ ```env
619
+ # === Connexion (obligatoires) ===
620
+ DB_DIALECT=sqlite # Dialecte (voir liste ci-dessus)
621
+ SGBD_URI=./data/myapp.db # URI de connexion
622
+
623
+ # === Schema management (hibernate.hbm2ddl.auto) ===
624
+ DB_SCHEMA_STRATEGY=update # none | validate | update | create | create-drop
625
+
626
+ # === Logging SQL (hibernate.show_sql / format_sql) ===
627
+ DB_SHOW_SQL=false # true = affiche les requêtes dans la console
628
+ DB_FORMAT_SQL=false # true = indente les requêtes affichées
629
+
630
+ # === Connection pool (hibernate.connection.pool_size) ===
631
+ DB_POOL_SIZE=10 # Nombre maximum de connexions simultanées
632
+
633
+ # === Cache de requêtes (hibernate.cache.use_second_level) ===
634
+ DB_CACHE_ENABLED=false # true = active le cache en mémoire
635
+ DB_CACHE_TTL=60 # Durée de vie du cache en secondes
636
+
637
+ # === Performance ===
638
+ DB_BATCH_SIZE=25 # Taille des lots pour les opérations bulk
639
+ ```
640
+
641
+ ---
642
+
643
+ ## 15. Comparaison des fonctionnalités
644
+
645
+ | Fonctionnalité | SQLite | PostgreSQL | MySQL | MariaDB | MongoDB | MSSQL | Oracle |
646
+ |----------------|--------|-----------|-------|---------|---------|-------|--------|
647
+ | CRUD complet | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
648
+ | Relations JOIN | ✅ | ✅ | ✅ | ✅ | ✅ (populate) | ✅ | ✅ |
649
+ | Agrégations | ✅ | ✅ | ✅ | ✅ | ✅ (pipeline) | ✅ | ✅ |
650
+ | Transactions | ✅ | ✅ | ✅ | ✅ | ✅ (4.0+) | ✅ | ✅ |
651
+ | Full-text search | LIKE | `tsvector` | FULLTEXT | FULLTEXT | `$text` | CONTAINS | CONTAINS |
652
+ | JSON natif | TEXT | JSONB | JSON | JSON | Natif | NVARCHAR | CLOB |
653
+ | Tableaux natifs | TEXT | `ARRAY[]` | TEXT | TEXT | Natif | TEXT | CLOB |
654
+ | Connexion pool | N/A | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
655
+ | SSL/TLS | N/A | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
656
+ | Schemaless | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ |
657
+ | Cloud managé | ❌ | Supabase, Neon | PlanetScale | ❌ | Atlas | Azure SQL | Oracle Cloud |
658
+ | Licence | Public domain | PostgreSQL | GPL/Commercial | GPL | SSPL | Commercial | Commercial |
659
+
660
+ ---
661
+
662
+ ## Choisir son dialecte
663
+
664
+ ```
665
+ Développement/prototypage rapide → SQLite
666
+ Application web classique → PostgreSQL (recommandé) ou MySQL
667
+ Entreprise Microsoft → MSSQL ou CockroachDB
668
+ Données documentaires → MongoDB
669
+ Grande scalabilité → PostgreSQL + replicas ou CockroachDB
670
+ Scalabilité mondiale → Google Cloud Spanner
671
+ Analytics temps réel → SAP HANA
672
+ Écosystème IBM → DB2
673
+ ```