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) {
|
||||
return customSelectQuery('SELECT * FROM config WHERE config_key = ?',
|
||||
variables: [
|
||||
Variable.withString(var1),
|
||||
],
|
||||
readsFrom: {
|
||||
config
|
||||
}).map(_rowToConfigData);
|
||||
variables: [Variable.withString(var1)],
|
||||
readsFrom: {config}).map(_rowToConfigData);
|
||||
}
|
||||
|
||||
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}',
|
||||
variables: [
|
||||
for (var $ in var1) Variable.withString($),
|
||||
...generatedclause.introducedVariables
|
||||
],
|
||||
readsFrom: {
|
||||
config
|
||||
|
@ -848,10 +845,7 @@ abstract class _$CustomTablesDb extends GeneratedDatabase {
|
|||
Future<int> writeConfig(String key, String value) {
|
||||
return customInsert(
|
||||
'REPLACE INTO config VALUES (:key, :value)',
|
||||
variables: [
|
||||
Variable.withString(key),
|
||||
Variable.withString(value),
|
||||
],
|
||||
variables: [Variable.withString(key), Variable.withString(value)],
|
||||
updates: {config},
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1333,9 +1333,7 @@ abstract class _$TodoDb extends GeneratedDatabase {
|
|||
Future<int> deleteTodoById(int var1) {
|
||||
return customUpdate(
|
||||
'DELETE FROM todos WHERE id = ?',
|
||||
variables: [
|
||||
Variable.withInt(var1),
|
||||
],
|
||||
variables: [Variable.withInt(var1)],
|
||||
updates: {todosTable},
|
||||
);
|
||||
}
|
||||
|
@ -1359,7 +1357,7 @@ abstract class _$TodoDb extends GeneratedDatabase {
|
|||
variables: [
|
||||
Variable.withString(var1),
|
||||
Variable.withString(var2),
|
||||
for (var $ in var3) Variable.withInt($),
|
||||
for (var $ in var3) Variable.withInt($)
|
||||
],
|
||||
readsFrom: {
|
||||
todosTable
|
||||
|
@ -1378,12 +1376,8 @@ abstract class _$TodoDb extends GeneratedDatabase {
|
|||
Selectable<TodoEntry> searchQuery(int id) {
|
||||
return customSelectQuery(
|
||||
'SELECT * FROM todos WHERE CASE WHEN -1 = :id THEN 1 ELSE id = :id END',
|
||||
variables: [
|
||||
Variable.withInt(id),
|
||||
],
|
||||
readsFrom: {
|
||||
todosTable
|
||||
}).map(_rowToTodoEntry);
|
||||
variables: [Variable.withInt(id)],
|
||||
readsFrom: {todosTable}).map(_rowToTodoEntry);
|
||||
}
|
||||
|
||||
Future<List<TodoEntry>> search(int id) {
|
||||
|
@ -1474,14 +1468,8 @@ mixin _$SomeDaoMixin on DatabaseAccessor<TodoDb> {
|
|||
Selectable<TodoEntry> todosForUserQuery(int user) {
|
||||
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',
|
||||
variables: [
|
||||
Variable.withInt(user),
|
||||
],
|
||||
readsFrom: {
|
||||
todosTable,
|
||||
sharedTodos,
|
||||
users
|
||||
}).map(_rowToTodoEntry);
|
||||
variables: [Variable.withInt(user)],
|
||||
readsFrom: {todosTable, sharedTodos, users}).map(_rowToTodoEntry);
|
||||
}
|
||||
|
||||
Future<List<TodoEntry>> todosForUser(int user) {
|
||||
|
|
|
@ -295,19 +295,28 @@ class QueryWriter {
|
|||
void _writeVariables() {
|
||||
_buffer..write('variables: [');
|
||||
|
||||
for (var variable in query.variables) {
|
||||
// for a regular variable: Variable.withInt(x),
|
||||
// for a list of vars: for (var $ in vars) Variable.withInt($),
|
||||
final constructor = createVariable[variable.type];
|
||||
final name = variable.dartParameterName;
|
||||
|
||||
if (variable.isArray) {
|
||||
_buffer.write('for (var \$ in $name) $constructor(\$)');
|
||||
} else {
|
||||
_buffer.write('$constructor($name)');
|
||||
var first = true;
|
||||
for (var element in query.elements) {
|
||||
if (!first) {
|
||||
_buffer.write(', ');
|
||||
}
|
||||
first = false;
|
||||
|
||||
_buffer.write(',');
|
||||
if (element is FoundVariable) {
|
||||
// for a regular variable: Variable.withInt(x),
|
||||
// for a list of vars: for (var $ in vars) Variable.withInt($),
|
||||
final constructor = createVariable[element.type];
|
||||
final name = element.dartParameterName;
|
||||
|
||||
if (element.isArray) {
|
||||
_buffer.write('for (var \$ in $name) $constructor(\$)');
|
||||
} else {
|
||||
_buffer.write('$constructor($name)');
|
||||
}
|
||||
} else if (element is FoundDartPlaceholder) {
|
||||
_buffer.write(
|
||||
'...${_placeholderContextName(element)}.introducedVariables');
|
||||
}
|
||||
}
|
||||
|
||||
_buffer..write(']');
|
||||
|
|
Loading…
Reference in New Issue