mirror of https://github.com/AMT-Cheif/drift.git
Write variables created in a dart template
This commit is contained in:
parent
29c0cdaf3f
commit
54c3dbc4b8
|
@ -821,12 +821,8 @@ abstract class _$CustomTablesDb extends GeneratedDatabase {
|
||||||
|
|
||||||
Selectable<ConfigData> readConfig(String var1) {
|
Selectable<ConfigData> readConfig(String var1) {
|
||||||
return customSelectQuery('SELECT * FROM config WHERE config_key = ?',
|
return customSelectQuery('SELECT * FROM config WHERE config_key = ?',
|
||||||
variables: [
|
variables: [Variable.withString(var1)],
|
||||||
Variable.withString(var1),
|
readsFrom: {config}).map(_rowToConfigData);
|
||||||
],
|
|
||||||
readsFrom: {
|
|
||||||
config
|
|
||||||
}).map(_rowToConfigData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Selectable<ConfigData> readMultiple(List<String> var1, OrderBy clause) {
|
Selectable<ConfigData> readMultiple(List<String> var1, OrderBy clause) {
|
||||||
|
@ -839,6 +835,7 @@ abstract class _$CustomTablesDb extends GeneratedDatabase {
|
||||||
'SELECT * FROM config WHERE config_key IN ($expandedvar1) ORDER BY ${generatedclause.sql}',
|
'SELECT * FROM config WHERE config_key IN ($expandedvar1) ORDER BY ${generatedclause.sql}',
|
||||||
variables: [
|
variables: [
|
||||||
for (var $ in var1) Variable.withString($),
|
for (var $ in var1) Variable.withString($),
|
||||||
|
...generatedclause.introducedVariables
|
||||||
],
|
],
|
||||||
readsFrom: {
|
readsFrom: {
|
||||||
config
|
config
|
||||||
|
@ -848,10 +845,7 @@ abstract class _$CustomTablesDb extends GeneratedDatabase {
|
||||||
Future<int> writeConfig(String key, String value) {
|
Future<int> writeConfig(String key, String value) {
|
||||||
return customInsert(
|
return customInsert(
|
||||||
'REPLACE INTO config VALUES (:key, :value)',
|
'REPLACE INTO config VALUES (:key, :value)',
|
||||||
variables: [
|
variables: [Variable.withString(key), Variable.withString(value)],
|
||||||
Variable.withString(key),
|
|
||||||
Variable.withString(value),
|
|
||||||
],
|
|
||||||
updates: {config},
|
updates: {config},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1333,9 +1333,7 @@ abstract class _$TodoDb extends GeneratedDatabase {
|
||||||
Future<int> deleteTodoById(int var1) {
|
Future<int> deleteTodoById(int var1) {
|
||||||
return customUpdate(
|
return customUpdate(
|
||||||
'DELETE FROM todos WHERE id = ?',
|
'DELETE FROM todos WHERE id = ?',
|
||||||
variables: [
|
variables: [Variable.withInt(var1)],
|
||||||
Variable.withInt(var1),
|
|
||||||
],
|
|
||||||
updates: {todosTable},
|
updates: {todosTable},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1359,7 +1357,7 @@ abstract class _$TodoDb extends GeneratedDatabase {
|
||||||
variables: [
|
variables: [
|
||||||
Variable.withString(var1),
|
Variable.withString(var1),
|
||||||
Variable.withString(var2),
|
Variable.withString(var2),
|
||||||
for (var $ in var3) Variable.withInt($),
|
for (var $ in var3) Variable.withInt($)
|
||||||
],
|
],
|
||||||
readsFrom: {
|
readsFrom: {
|
||||||
todosTable
|
todosTable
|
||||||
|
@ -1378,12 +1376,8 @@ abstract class _$TodoDb extends GeneratedDatabase {
|
||||||
Selectable<TodoEntry> searchQuery(int id) {
|
Selectable<TodoEntry> searchQuery(int id) {
|
||||||
return customSelectQuery(
|
return customSelectQuery(
|
||||||
'SELECT * FROM todos WHERE CASE WHEN -1 = :id THEN 1 ELSE id = :id END',
|
'SELECT * FROM todos WHERE CASE WHEN -1 = :id THEN 1 ELSE id = :id END',
|
||||||
variables: [
|
variables: [Variable.withInt(id)],
|
||||||
Variable.withInt(id),
|
readsFrom: {todosTable}).map(_rowToTodoEntry);
|
||||||
],
|
|
||||||
readsFrom: {
|
|
||||||
todosTable
|
|
||||||
}).map(_rowToTodoEntry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<TodoEntry>> search(int id) {
|
Future<List<TodoEntry>> search(int id) {
|
||||||
|
@ -1474,14 +1468,8 @@ mixin _$SomeDaoMixin on DatabaseAccessor<TodoDb> {
|
||||||
Selectable<TodoEntry> todosForUserQuery(int user) {
|
Selectable<TodoEntry> todosForUserQuery(int user) {
|
||||||
return customSelectQuery(
|
return customSelectQuery(
|
||||||
'SELECT t.* FROM todos t INNER JOIN shared_todos st ON st.todo = t.id INNER JOIN users u ON u.id = st.user WHERE u.id = :user',
|
'SELECT t.* FROM todos t INNER JOIN shared_todos st ON st.todo = t.id INNER JOIN users u ON u.id = st.user WHERE u.id = :user',
|
||||||
variables: [
|
variables: [Variable.withInt(user)],
|
||||||
Variable.withInt(user),
|
readsFrom: {todosTable, sharedTodos, users}).map(_rowToTodoEntry);
|
||||||
],
|
|
||||||
readsFrom: {
|
|
||||||
todosTable,
|
|
||||||
sharedTodos,
|
|
||||||
users
|
|
||||||
}).map(_rowToTodoEntry);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<TodoEntry>> todosForUser(int user) {
|
Future<List<TodoEntry>> todosForUser(int user) {
|
||||||
|
|
|
@ -295,19 +295,28 @@ class QueryWriter {
|
||||||
void _writeVariables() {
|
void _writeVariables() {
|
||||||
_buffer..write('variables: [');
|
_buffer..write('variables: [');
|
||||||
|
|
||||||
for (var variable in query.variables) {
|
var first = true;
|
||||||
|
for (var element in query.elements) {
|
||||||
|
if (!first) {
|
||||||
|
_buffer.write(', ');
|
||||||
|
}
|
||||||
|
first = false;
|
||||||
|
|
||||||
|
if (element is FoundVariable) {
|
||||||
// for a regular variable: Variable.withInt(x),
|
// for a regular variable: Variable.withInt(x),
|
||||||
// for a list of vars: for (var $ in vars) Variable.withInt($),
|
// for a list of vars: for (var $ in vars) Variable.withInt($),
|
||||||
final constructor = createVariable[variable.type];
|
final constructor = createVariable[element.type];
|
||||||
final name = variable.dartParameterName;
|
final name = element.dartParameterName;
|
||||||
|
|
||||||
if (variable.isArray) {
|
if (element.isArray) {
|
||||||
_buffer.write('for (var \$ in $name) $constructor(\$)');
|
_buffer.write('for (var \$ in $name) $constructor(\$)');
|
||||||
} else {
|
} else {
|
||||||
_buffer.write('$constructor($name)');
|
_buffer.write('$constructor($name)');
|
||||||
}
|
}
|
||||||
|
} else if (element is FoundDartPlaceholder) {
|
||||||
_buffer.write(',');
|
_buffer.write(
|
||||||
|
'...${_placeholderContextName(element)}.introducedVariables');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_buffer..write(']');
|
_buffer..write(']');
|
||||||
|
|
Loading…
Reference in New Issue