Skip to content

Commit 39ee7e0

Browse files
authored
Merge pull request #1249 from appwrite/fix-prefix-table-name
2 parents cd71267 + 123771d commit 39ee7e0

File tree

7 files changed

+47
-47
lines changed

7 files changed

+47
-47
lines changed

templates/cli/lib/type-generation/languages/csharp.js.twig

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ const { AttributeType } = require('../attribute');
33
const { LanguageMeta } = require("./language");
44

55
class CSharp extends LanguageMeta {
6-
getType(attribute, collections) {
6+
getType(attribute, collections, collectionName) {
77
let type = "";
88
switch (attribute.type) {
99
case AttributeType.STRING:
1010
case AttributeType.EMAIL:
1111
case AttributeType.DATETIME:
1212
type = "string";
1313
if (attribute.format === AttributeType.ENUM) {
14-
type = LanguageMeta.toPascalCase(attribute.key);
14+
type = LanguageMeta.toPascalCase(collectionName) + LanguageMeta.toPascalCase(attribute.key);
1515
}
1616
break;
1717
case AttributeType.INTEGER:
@@ -60,7 +60,7 @@ namespace Appwrite.Models
6060
<% for (const attribute of collection.attributes) { -%>
6161
<% if (attribute.format === 'enum') { -%>
6262

63-
public enum <%- toPascalCase(attribute.key) %> {
63+
public enum <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %> {
6464
<% for (const [index, element] of Object.entries(attribute.elements) ) { -%>
6565
[JsonPropertyName("<%- element %>")]
6666
<%- toPascalCase(element) %><% if (index < attribute.elements.length - 1) { %>,<% } %>
@@ -72,13 +72,13 @@ public class <%= toPascalCase(collection.name) %>
7272
{
7373
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
7474
[JsonPropertyName("<%- attribute.key %>")]
75-
public <%- getType(attribute, collections) %> <%= toPascalCase(attribute.key) %> { get; private set; }
75+
public <%- getType(attribute, collections, collection.name) %> <%= toPascalCase(attribute.key) %> { get; private set; }
7676

7777
<% } -%>
7878

7979
public <%= toPascalCase(collection.name) %>(
8080
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
81-
<%- getType(attribute, collections) %> <%= toCamelCase(attribute.key) %><% if (index < collection.attributes.length - 1) { %>,<% } %>
81+
<%- getType(attribute, collections, collection.name) %> <%= toCamelCase(attribute.key) %><% if (index < collection.attributes.length - 1) { %>,<% } %>
8282
<% } -%>
8383
)
8484
{
@@ -93,9 +93,9 @@ public class <%= toPascalCase(collection.name) %>
9393
// ENUM
9494
if (attribute.format === 'enum') {
9595
if (attribute.array) {
96-
-%>((IEnumerable<object>)map["<%- attribute.key %>"]).Select(e => Enum.Parse<Models.<%- toPascalCase(attribute.key) %>>(e.ToString()!, true)).ToList()<%
96+
-%>((IEnumerable<object>)map["<%- attribute.key %>"]).Select(e => Enum.Parse<Models.<%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %>>(e.ToString()!, true)).ToList()<%
9797
} else {
98-
-%>Enum.Parse<Models.<%- toPascalCase(attribute.key) %>>(map["<%- attribute.key %>"].ToString()!, true)<%
98+
-%>Enum.Parse<Models.<%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %>>(map["<%- attribute.key %>"].ToString()!, true)<%
9999
}
100100
// RELATIONSHIP
101101
} else if (attribute.type === 'relationship') {
@@ -122,7 +122,7 @@ public class <%= toPascalCase(collection.name) %>
122122
} else if (attribute.type === 'double') {
123123
-%><%- !attribute.required ? 'map["' + attribute.key + '"] == null ? null : ' : '' %>Convert.ToDouble(map["<%- attribute.key %>"])<%
124124
} else if (attribute.type === 'boolean') {
125-
-%>(<%- getType(attribute, collections) %>)map["<%- attribute.key %>"]<%
125+
-%>(<%- getType(attribute, collections, collection.name) %>)map["<%- attribute.key %>"]<%
126126
} else if (attribute.type === 'string' || attribute.type === 'datetime' || attribute.type === 'email') {
127127
-%>map["<%- attribute.key %>"]<%- !attribute.required ? '?' : '' %>.ToString()<%- attribute.required ? '!' : ''%><%
128128
} else {

templates/cli/lib/type-generation/languages/dart.js.twig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ class Dart extends LanguageMeta {
4040
return 'appwrite';
4141
}
4242

43-
getType(attribute, collections) {
43+
getType(attribute, collections, collectionName) {
4444
let type = "";
4545
switch (attribute.type) {
4646
case AttributeType.STRING:
4747
case AttributeType.EMAIL:
4848
case AttributeType.DATETIME:
4949
type = "String";
5050
if (attribute.format === AttributeType.ENUM) {
51-
type = LanguageMeta.toPascalCase(attribute.key);
51+
type = LanguageMeta.toPascalCase(collectionName) + LanguageMeta.toPascalCase(attribute.key);
5252
}
5353
break;
5454
case AttributeType.INTEGER:
@@ -103,7 +103,7 @@ import '<%- toSnakeCase(related.name) %>.dart';
103103

104104
<% for (const attribute of __attrs) { -%>
105105
<% if (attribute.format === '${AttributeType.ENUM}') { -%>
106-
enum <%- toPascalCase(attribute.key) %> {
106+
enum <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %> {
107107
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
108108
<%- strict ? toCamelCase(element) : element %><% if (index < attribute.elements.length - 1) { -%>,<% } %>
109109
<% } -%>
@@ -113,7 +113,7 @@ enum <%- toPascalCase(attribute.key) %> {
113113
<% } -%>
114114
class <%= toPascalCase(collection.name) %> {
115115
<% for (const [index, attribute] of Object.entries(__attrs)) { -%>
116-
<%- getType(attribute, collections) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %>;
116+
<%- getType(attribute, collections, collection.name) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %>;
117117
<% } -%>
118118

119119
<%= toPascalCase(collection.name) %>({
@@ -128,10 +128,10 @@ class <%= toPascalCase(collection.name) %> {
128128
<%= strict ? toCamelCase(attribute.key) : attribute.key %>: <% if (attribute.type === '${AttributeType.STRING}' || attribute.type === '${AttributeType.EMAIL}' || attribute.type === '${AttributeType.DATETIME}') { -%>
129129
<% if (attribute.format === '${AttributeType.ENUM}') { -%>
130130
<% if (attribute.array) { -%>
131-
(map['<%= attribute.key %>'] as List<dynamic>?)?.map((e) => <%- toPascalCase(attribute.key) %>.values.firstWhere((element) => element.name == e)).toList()<% } else { -%>
131+
(map['<%= attribute.key %>'] as List<dynamic>?)?.map((e) => <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %>.values.firstWhere((element) => element.name == e)).toList()<% } else { -%>
132132
<% if (!attribute.required) { -%>
133-
map['<%= attribute.key %>'] != null ? <%- toPascalCase(attribute.key) %>.values.where((e) => e.name == map['<%= attribute.key %>']).firstOrNull : null<% } else { -%>
134-
<%- toPascalCase(attribute.key) %>.values.firstWhere((e) => e.name == map['<%= attribute.key %>'])<% } -%>
133+
map['<%= attribute.key %>'] != null ? <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %>.values.where((e) => e.name == map['<%= attribute.key %>']).firstOrNull : null<% } else { -%>
134+
<%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %>.values.firstWhere((e) => e.name == map['<%= attribute.key %>'])<% } -%>
135135
<% } -%>
136136
<% } else { -%>
137137
<% if (attribute.array) { -%>

templates/cli/lib/type-generation/languages/java.js.twig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ const { AttributeType } = require('../attribute');
33
const { LanguageMeta } = require("./language");
44

55
class Java extends LanguageMeta {
6-
getType(attribute, collections) {
6+
getType(attribute, collections, collectionName) {
77
let type = "";
88
switch (attribute.type) {
99
case AttributeType.STRING:
1010
case AttributeType.EMAIL:
1111
case AttributeType.DATETIME:
1212
type = "String";
1313
if (attribute.format === AttributeType.ENUM) {
14-
type = LanguageMeta.toPascalCase(attribute.key);
14+
type = LanguageMeta.toPascalCase(collectionName) + LanguageMeta.toPascalCase(attribute.key);
1515
}
1616
break;
1717
case AttributeType.INTEGER:
@@ -61,7 +61,7 @@ public class <%- toPascalCase(collection.name) %> {
6161
<% for (const attribute of collection.attributes) { -%>
6262
<% if (attribute.format === 'enum') { -%>
6363

64-
public enum <%- toPascalCase(attribute.key) %> {
64+
public enum <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %> {
6565
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
6666
<%- strict ? toUpperSnakeCase(element) : element %><%- index < attribute.elements.length - 1 ? ',' : ';' %>
6767
<% } -%>
@@ -70,15 +70,15 @@ public class <%- toPascalCase(collection.name) %> {
7070
<% } -%>
7171
<% } -%>
7272
<% for (const attribute of collection.attributes) { -%>
73-
private <%- getType(attribute, collections) %> <%- strict ? toCamelCase(attribute.key) : attribute.key %>;
73+
private <%- getType(attribute, collections, collection.name) %> <%- strict ? toCamelCase(attribute.key) : attribute.key %>;
7474
<% } -%>
7575

7676
public <%- toPascalCase(collection.name) %>() {
7777
}
7878

7979
public <%- toPascalCase(collection.name) %>(
8080
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
81-
<%- getType(attribute, collections) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %><%- index < collection.attributes.length - 1 ? ',' : '' %>
81+
<%- getType(attribute, collections, collection.name) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %><%- index < collection.attributes.length - 1 ? ',' : '' %>
8282
<% } -%>
8383
) {
8484
<% for (const attribute of collection.attributes) { -%>
@@ -87,11 +87,11 @@ public class <%- toPascalCase(collection.name) %> {
8787
}
8888

8989
<% for (const attribute of collection.attributes) { -%>
90-
public <%- getType(attribute, collections) %> get<%- toPascalCase(attribute.key) %>() {
90+
public <%- getType(attribute, collections, collection.name) %> get<%- toPascalCase(attribute.key) %>() {
9191
return <%= strict ? toCamelCase(attribute.key) : attribute.key %>;
9292
}
9393

94-
public void set<%- toPascalCase(attribute.key) %>(<%- getType(attribute, collections) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %>) {
94+
public void set<%- toPascalCase(attribute.key) %>(<%- getType(attribute, collections, collection.name) %> <%= strict ? toCamelCase(attribute.key) : attribute.key %>) {
9595
this.<%= strict ? toCamelCase(attribute.key) : attribute.key %> = <%= strict ? toCamelCase(attribute.key) : attribute.key %>;
9696
}
9797

templates/cli/lib/type-generation/languages/kotlin.js.twig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ const { AttributeType } = require('../attribute');
33
const { LanguageMeta } = require("./language");
44

55
class Kotlin extends LanguageMeta {
6-
getType(attribute, collections) {
6+
getType(attribute, collections, collectionName) {
77
let type = "";
88
switch (attribute.type) {
99
case AttributeType.STRING:
1010
case AttributeType.EMAIL:
1111
case AttributeType.DATETIME:
1212
type = "String";
1313
if (attribute.format === AttributeType.ENUM) {
14-
type = LanguageMeta.toPascalCase(attribute.key);
14+
type = LanguageMeta.toPascalCase(collectionName) + LanguageMeta.toPascalCase(attribute.key);
1515
}
1616
break;
1717
case AttributeType.INTEGER:
@@ -61,7 +61,7 @@ import <%- toPascalCase(collections.find(c => c.$id === attribute.relatedCollect
6161

6262
<% for (const attribute of collection.attributes) { -%>
6363
<% if (attribute.format === 'enum') { -%>
64-
enum class <%- toPascalCase(attribute.key) %> {
64+
enum class <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %> {
6565
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
6666
<%- strict ? toUpperSnakeCase(element) : element %><%- index < attribute.elements.length - 1 ? ',' : '' %>
6767
<% } -%>
@@ -71,7 +71,7 @@ enum class <%- toPascalCase(attribute.key) %> {
7171
<% } -%>
7272
data class <%- toPascalCase(collection.name) %>(
7373
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
74-
val <%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute, collections) %><% if (index < collection.attributes.length - 1) { %>,<% } %>
74+
val <%- strict ? toCamelCase(attribute.key) : attribute.key %>: <%- getType(attribute, collections, collection.name) %><% if (index < collection.attributes.length - 1) { %>,<% } %>
7575
<% } -%>
7676
)
7777
`;

templates/cli/lib/type-generation/languages/php.js.twig

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { AttributeType } = require('../attribute');
33
const { LanguageMeta } = require("./language");
44

55
class PHP extends LanguageMeta {
6-
getType(attribute, collections) {
6+
getType(attribute, collections, collectionName) {
77
if (attribute.array) {
88
return "array";
99
}
@@ -14,7 +14,7 @@ class PHP extends LanguageMeta {
1414
case AttributeType.DATETIME:
1515
type = "string";
1616
if (attribute.format === AttributeType.ENUM) {
17-
type = LanguageMeta.toPascalCase(attribute.key);
17+
type = LanguageMeta.toPascalCase(collectionName) + LanguageMeta.toPascalCase(attribute.key);
1818
}
1919
break;
2020
case AttributeType.INTEGER:
@@ -60,25 +60,25 @@ use Appwrite\\Models\\<%- toPascalCase(collections.find(c => c.$id === attribute
6060
<% } -%>
6161
<% for (const attribute of collection.attributes) { -%>
6262
<% if (attribute.format === 'enum') { -%>
63-
enum <%- toPascalCase(attribute.key) %>: string {
63+
enum <%- toPascalCase(collection.name) %><%- toPascalCase(attribute.key) %>: string {
6464
<% for (const [index, element] of Object.entries(attribute.elements)) { -%>
65-
case <%- strict ? toUpperSnakeCase(element) : element %> = '<%- element %>';
65+
case <%- toUpperSnakeCase(element) %> = '<%- element %>';
6666
<% } -%>
6767
}
6868
6969
<% } -%>
7070
<% } -%>
7171
class <%- toPascalCase(collection.name) %> {
7272
<% for (const attribute of collection.attributes ){ -%>
73-
private <%- getType(attribute, collections) %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %>;
73+
private <%- getType(attribute, collections, collection.name) %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %>;
7474
<% } -%>
7575
7676
public function __construct(
7777
<% for (const attribute of collection.attributes ){ -%>
7878
<% if (attribute.required) { -%>
79-
<%- getType(attribute, collections).replace('|null', '') %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %><% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
79+
<%- getType(attribute, collections, collection.name).replace('|null', '') %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %><% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
8080
<% } else { -%>
81-
?<%- getType(attribute, collections).replace('|null', '') %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %> = null<% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
81+
?<%- getType(attribute, collections, collection.name).replace('|null', '') %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %> = null<% if (collection.attributes.indexOf(attribute) < collection.attributes.length - 1) { %>,<% } %>
8282
<% } -%>
8383
<% } -%>
8484
) {
@@ -88,11 +88,11 @@ class <%- toPascalCase(collection.name) %> {
8888
}
8989
9090
<% for (const [index, attribute] of Object.entries(collection.attributes)) { -%>
91-
public function get<%- toPascalCase(attribute.key) %>(): <%- getType(attribute, collections) %> {
91+
public function get<%- toPascalCase(attribute.key) %>(): <%- getType(attribute, collections, collection.name) %> {
9292
return $this-><%- strict ? toCamelCase(attribute.key) : attribute.key %>;
9393
}
9494
95-
public function set<%- toPascalCase(attribute.key) %>(<%- getType(attribute, collections) %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %>): void {
95+
public function set<%- toPascalCase(attribute.key) %>(<%- getType(attribute, collections, collection.name) %> $<%- strict ? toCamelCase(attribute.key) : attribute.key %>): void {
9696
$this-><%- strict ? toCamelCase(attribute.key) : attribute.key %> = $<%- strict ? toCamelCase(attribute.key) : attribute.key %>;
9797
}
9898
<% if (index < collection.attributes.length - 1) { %>

0 commit comments

Comments
 (0)