sqltree 0.0.1+1 copy "sqltree: ^0.0.1+1" to clipboard
sqltree: ^0.0.1+1 copied to clipboard

outdatedDart 1 only

A library for building sql queries through a tree representation.

example/sqltree_example.dart

// Copyright (c) 2016, Roberto Tassi. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

import 'package:sqltree/sqltree.dart' as sql;

main() {
  sql.node("ciao").clone();

  var select = sql.select("*")
        ..from(sql.joins("tabella"))
        ..where(sql.equal("a", sql.parameter("par1")))
        ..where(sql.setReference("ref1", sql.equal("b", sql.parameter("par2"))))
        ..where(sql.qualify("a", "1", "2", "3"))
        ..where(sql.setReference("ref2", sql.sqlInTuple("a")))
        ..where(sql.sqlIn("a", sql.setReference("ref3", sql.tuple())))
        ..where(sql.sqlInTuple("a"))
        ..limit(10)
        ..offset(200)
      ;

  select.whereClause.children.last.children.last
      .addChildren(sql.text("OPEN", "CLOSED"));

  select.getSingleNodeByReference("ref1").disable();

  select
      .getSingleNodeByReference("ref2")
      .children
      .last
      .addChildren(sql.text("OPEN", "CLOSED"));

  select
      .getSingleNodeByReference("ref3")
      .addChildren(sql.text("OPEN", "CLOSED"));

  print(sql.prettify(sql.format(select)));

  var conversion = sql.convert(sql.format(select));

  print(sql.prettify(conversion.positionalParameterSql));
  print(conversion.positionalParameterNames);

  print(sql.prettify(sql.format(select.clone())));

  var cloned = select.clone();

  cloned.getSingleNodeByReference("ref1").disable();

  print(sql.prettify(sql.format(cloned)));

  // select.clone(freeze: true).getSingleNodeByReference("ref1").disable();
  // select.clone(freeze: true).clone().getSingleNodeByReference("ref1").disable();

  var freezed = select.clone(freeze: true).clone(freeze: false);

  freezed
      .getSingleNodeByReference("ref3")
      .addChildren(sql.text("OPEN", "CLOSED"));

  print(sql.prettify(sql.format(freezed)));

  select = select.clone(freeze: false);

  print(select == select.clone(freeze: false));

  select = select.clone(freeze: true);

  print(select == select.clone(freeze: true));

  print(sql.prettify(sql.format(sql.text(r"ci'\'ao").single)));

  print(sql.prettify(sql.format(sql.select(sql.function("coalesce", "ID", "REF_ID")))));
}
0
likes
0
points
18
downloads

Publisher

unverified uploader

Weekly Downloads

A library for building sql queries through a tree representation.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

collection

More

Packages that depend on sqltree