Skip to content

Commit 2e5b310

Browse files
committed
update
1 parent 5e2f187 commit 2e5b310

62 files changed

Lines changed: 2735 additions & 165 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Changelog
22

3+
## [0.16.0]
4+
5+
- Released @ 6/2026 (UTC)
6+
- New: `tableName:` annotation slot — explicit override for the DBML table name; falls back to stripping the `Model` marker (prefix *or* suffix) from the class and snake-casing. No automatic English pluralisation. `ModelUser``user`, `HelloModel``hello`, `ModelModel``model`
7+
- New: `schema:` annotation slot acts as the DBML emission gate. Models without `schema:` are skipped (nested/embedded children drop out naturally). Distinct schema values produce one `<schema>.dbml` file each — multi-schema projects supported out of the box
8+
- New: `static const tableName` emitted on every generated class — runtime introspection without the annotation handshake (`ModelUser.tableName`)
9+
- New: `XxxFieldNames.$values` / `$primaryKey` / `$foreignKeys` — surface declaration-order field names, the primary key, and the foreign-key → referenced-class map without reflection
10+
- New: `references:` accepts a `String` literal (`references: 'ModelUser'`) in addition to a Type literal — lets cross-package references skip the import chain
11+
- New: FK target column now resolves to the parent's actual primary-key column (e.g. `permissions.key`) instead of hardcoded `.id`; FK target table honours the parent's explicit `tableName:`
12+
- New: DBML emitter's `--output` is now treated as the directory for per-schema files (a `*.dbml` value uses its parent dir — old ergonomics still work)
13+
- Fix: default template URL is now version-pinned (`v$version`) — old binaries no longer pull `main` template changes silently. Falls back to `main` only for dev checkouts
14+
- Fix: no-pluralisation rule replaces the previous naive English heuristic that produced `activitys` / `contact_address` / etc.
15+
- Pulls in df_generate_dart_models_core 0.11.0
16+
317
## [0.15.0]
418

519
- Released @ 6/2026 (UTC)

bin/df_generate_dart_models.dart

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,48 @@
1111
// ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
1212
//.title~
1313

14+
import 'dart:io';
15+
import 'dart:isolate';
16+
1417
import 'package:df_generate_dart_models/df_generate_dart_models.dart';
1518

1619
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
1720

1821
void main(List<String> args) async {
22+
final version = await _resolvePackageVersion();
23+
final tag = version != null ? 'v$version' : 'main';
1924
await generateDartModels(
2025
args,
2126
defaultTemplatePathOrUrl:
22-
'https://raw.githubusercontent.com/dev-cetera/df_generate_dart_models/main/templates/featured_v1.dart.md',
27+
'https://raw.githubusercontent.com/dev-cetera/df_generate_dart_models/$tag/templates/featured_v1.dart.md',
2328
);
2429
}
30+
31+
/// Resolves the installed package's version from its own pubspec.yaml so the
32+
/// default template URL points at the matching git tag.
33+
///
34+
/// Without this, every binary — including ones installed months ago — would
35+
/// pull the *current* `main` template, so any breaking interpolator/template
36+
/// change in HEAD would silently corrupt old users' generated output.
37+
///
38+
/// Returns `null` if the pubspec can't be located or parsed; the caller then
39+
/// falls back to `main`, which preserves historical behaviour for
40+
/// development checkouts where this lookup may not succeed.
41+
Future<String?> _resolvePackageVersion() async {
42+
try {
43+
final libraryUri = await Isolate.resolvePackageUri(
44+
Uri.parse('package:df_generate_dart_models/df_generate_dart_models.dart'),
45+
);
46+
if (libraryUri == null) return null;
47+
final libDir = File.fromUri(libraryUri).parent;
48+
final pubspec = File('${libDir.parent.path}/pubspec.yaml');
49+
if (!pubspec.existsSync()) return null;
50+
final match = RegExp(
51+
r'^version:\s*(\S+)',
52+
multiLine: true,
53+
).firstMatch(pubspec.readAsStringSync());
54+
return match?.group(1);
55+
} catch (_) {
56+
return null;
57+
}
58+
}

0 commit comments

Comments
 (0)