oktopios-orm 0.6.0__tar.gz → 0.7.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: oktopios-orm
3
- Version: 0.6.0
3
+ Version: 0.7.0
4
4
  Summary: ORM pour le langage Oktopios — modeles decores, migrations, query-builder (facon Doctrine / Django ORM)
5
5
  Author: Mouanwiya Ali Soule
6
6
  License: MIT License
@@ -1,2 +1,2 @@
1
1
  """oktopios-orm — ORM pour le langage Oktopios."""
2
- __version__ = "0.6.0"
2
+ __version__ = "0.7.0"
@@ -209,6 +209,43 @@ class Repo {
209
209
  return nouvelId
210
210
  }
211
211
 
212
+ // Met à jour l'entité par son @Id (colonnes et clés étrangères @ManyToOne).
213
+ // Renvoie le nombre de lignes modifiées.
214
+ fun update(entity: any): int {
215
+ var idf = this.schema.idField(entity)
216
+ var sets = ""
217
+ var valeurs = []
218
+ for (f in Type.fields(entity)) {
219
+ if (f != idf) {
220
+ if (this.schema.isCollection(entity, f) == false) {
221
+ var col = ""
222
+ var valeur = null
223
+ if (this.schema.isRelation(entity, f) == true) {
224
+ col = this.schema.fkColumn(entity, f)
225
+ var lie = Type.get(entity, f)
226
+ if (lie != null) {
227
+ valeur = Type.get(lie, this.schema.idField(lie))
228
+ }
229
+ } else {
230
+ col = this.schema.columnName(entity, f)
231
+ valeur = Type.get(entity, f)
232
+ }
233
+ if (sets != "") { sets = sets + ", " }
234
+ sets = sets + col + " = ?"
235
+ valeurs = valeurs + [valeur]
236
+ }
237
+ }
238
+ }
239
+ valeurs = valeurs + [Type.get(entity, idf)]
240
+ var sql = "UPDATE " + this.table + " SET " + sets + " WHERE " + this.idColumn() + " = ?"
241
+ return DataImport.execSQL(this.db, sql, valeurs)
242
+ }
243
+
244
+ // Supprime une entité par son identifiant.
245
+ fun removeById(id: any): int {
246
+ return this.remove(this.idColumn(), id)
247
+ }
248
+
212
249
  // Lie `entity` à `lie` via la table de jointure du champ @ManyToMany `f`.
213
250
  fun attach(entity: any, f: string, lie: any): int {
214
251
  var jt = this.schema.m2mJoin(entity, f)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: oktopios-orm
3
- Version: 0.6.0
3
+ Version: 0.7.0
4
4
  Summary: ORM pour le langage Oktopios — modeles decores, migrations, query-builder (facon Doctrine / Django ORM)
5
5
  Author: Mouanwiya Ali Soule
6
6
  License: MIT License
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "oktopios-orm"
7
- version = "0.6.0"
7
+ version = "0.7.0"
8
8
  description = "ORM pour le langage Oktopios — modeles decores, migrations, query-builder (facon Doctrine / Django ORM)"
9
9
  readme = "README.md"
10
10
  license = { file = "LICENSE" }
@@ -358,3 +358,32 @@ def test_orm_migration_rollback(tmp_path):
358
358
  assert "last=002_u" in out, out # rollbackLast renvoie la dernière
359
359
  assert "etat=['001_t']" in out, out # 002 retirée du suivi
360
360
  assert "u=0" in out, out # table u supprimée par le `down`
361
+
362
+
363
+ PROG_UPDATE = '''use "oktopios_orm/orm.okp"
364
+ @Entity("p")
365
+ class P {{ @Id var id: int @Column("nom") var nom: string }}
366
+ var db = "{db}"
367
+ var schema = new Schema()
368
+ schema.migrate(db, new P())
369
+ var repo = new Repo(db, new P())
370
+ var a = new P()
371
+ a.nom = "avant"
372
+ repo.save(a)
373
+ a.nom = "apres"
374
+ print("upd=" + repo.update(a))
375
+ var relu = repo.find(a.id)
376
+ print("nom=" + relu.nom)
377
+ print("del=" + repo.removeById(a.id))
378
+ var apres = repo.find(a.id)
379
+ if (apres == null) {{ print("gone=1") }}
380
+ '''
381
+
382
+
383
+ def test_orm_update_and_remove_by_id(tmp_path):
384
+ db = str(tmp_path / "up.db").replace("\\", "/")
385
+ out = _run_okp(PROG_UPDATE.format(db=db), tmp_path)
386
+ assert "upd=1" in out, out
387
+ assert "nom=apres" in out, out
388
+ assert "del=1" in out, out
389
+ assert "gone=1" in out, out
File without changes
File without changes
File without changes