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.
- {oktopios_orm-0.6.0 → oktopios_orm-0.7.0}/PKG-INFO +1 -1
- {oktopios_orm-0.6.0 → oktopios_orm-0.7.0}/oktopios_orm/__init__.py +1 -1
- {oktopios_orm-0.6.0 → oktopios_orm-0.7.0}/oktopios_orm/orm.okp +37 -0
- {oktopios_orm-0.6.0 → oktopios_orm-0.7.0}/oktopios_orm.egg-info/PKG-INFO +1 -1
- {oktopios_orm-0.6.0 → oktopios_orm-0.7.0}/pyproject.toml +1 -1
- {oktopios_orm-0.6.0 → oktopios_orm-0.7.0}/tests/test_orm.py +29 -0
- {oktopios_orm-0.6.0 → oktopios_orm-0.7.0}/LICENSE +0 -0
- {oktopios_orm-0.6.0 → oktopios_orm-0.7.0}/README.md +0 -0
- {oktopios_orm-0.6.0 → oktopios_orm-0.7.0}/oktopios_orm.egg-info/SOURCES.txt +0 -0
- {oktopios_orm-0.6.0 → oktopios_orm-0.7.0}/oktopios_orm.egg-info/dependency_links.txt +0 -0
- {oktopios_orm-0.6.0 → oktopios_orm-0.7.0}/oktopios_orm.egg-info/requires.txt +0 -0
- {oktopios_orm-0.6.0 → oktopios_orm-0.7.0}/oktopios_orm.egg-info/top_level.txt +0 -0
- {oktopios_orm-0.6.0 → oktopios_orm-0.7.0}/setup.cfg +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"""oktopios-orm — ORM pour le langage Oktopios."""
|
|
2
|
-
__version__ = "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)
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "oktopios-orm"
|
|
7
|
-
version = "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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|