angel3_orm 10.3.0
angel3_orm: ^10.3.0 copied to clipboard
Runtime support for Angel3 ORM. Includes base classes for queries.
Change Log #
10.3.0 #
New in 10.3.0 #
- Errors:
QueryExecutor.classifyErrortells the kind of an error of the database's driver that a query failed with, as aQueryErrorof aQueryErrorKind(a unique,NOT NULLor foreign key violation, or an invalid value) and its column or constraint, without its values, so that it can be answered without depending on the driver, asangel3_orm_servicedoes. The error is still thrown as the driver throws it. An executor classifies none by default - Migrations:
ColumnType.uuid, a UUID, whichangel3_migration_runnerdeclares as each database has it:uuidon PostgreSQL,CHAR(36)of a binary collation on MySQL and MariaDB, andTEXTon SQLite
Fixes in 10.3.0 #
- JSON queries: The conditions of a JSON column, of
MapSqlExpressionBuilderandListSqlExpressionBuilder, and of its properties, aswhere.profile['first_name'].asString?.equals('Ana'), are written in the SQL of the database of the query's executor, where they were PostgreSQL's (::jsonb,->>), which MySQL, MariaDB and SQLite rejected. On MySQL and MariaDB, ofJSON_EXTRACT,JSON_CONTAINSandJSON_TYPE:equalsof a column is true of JSON that each contains, so of arrays of the same values in any order. On SQLite, ofjson_extractandjson_type:equalscompares the JSON minified, so of the same keys in the same order, as a serializer writes them, andcontainsandcontainsPairthrow anUnsupportedError. A property readasDateTimeis PostgreSQL's only, and a key with a"or a backslash is anArgumentErrorelsewhere. A property isNULLwhere it is missing, a JSONnull, or not of the type it is read as. A query compiled without an executor, as ofcompile({}), is written for PostgreSQL, as before - JSON values: A value cast to
jsonorjsonb, as the generatedcastsof aListfield are, is cast on PostgreSQL only, as MySQL and MariaDB have nojsonbtype, and SQLite stored a list as0
10.2.0 #
Breaking changes in 10.2.0 #
- Breaking:
DialecthasrowLockSupport, whether aSELECTmay haveFOR UPDATE, which a class that implements it must give. A dialect withoutwritableCteSupportis written for as MySQL is, where onlyMySQLDialectwas, and one withoutrowLockSupportgets noFOR UPDATE
New in 10.2.0 #
- Dialects:
SqliteDialect, for SQLite 3.35 or later, whichangel3_orm_sqliteuses. Queries are written for it as for MySQL, withoutFOR UPDATE, as SQLite has none.SqliteDialect.formatDateTimegives aDateTimeas SQLite stores it, UTC text that sorts in time order
10.1.0 #
Breaking changes in 10.1.0 #
- Breaking: An update or an insert returns each row it wrote, whatever it joins: with the columns of a join that does not match as
NULL, where it returned no row. A row is returned once with acrossJoin, where it was once for each row of that table, but once for each match of a join - Breaking: An update of a query with a join other than a
LEFT JOINupdates only the rows of the join, which are those it returns, where it updated every row that matchedwhere, and returned only those. A row without a match is no longer updated. On MySQL, a query that selects no id throws aStateErrorfor such a join - Breaking: On PostgreSQL, 16 or later is required, of which a JSON property
asDateTimeusespg_input_is_valid: it fails with an error on an earlier version - Breaking:
groupBy,crossJoin,join,leftJoin,rightJoin,fullOuterJoinandselfJointhrow anArgumentErrorfor a name that is not an identifier, which may be quoted ("order",`order`) and qualified (table.column), and has no leading$, as$$starts a string and$1is a parameter on PostgreSQL, asorderBydoes when compiled, where it was written into the SQL as given, so a value from a request could add SQL to a query. This covers table names, keys, aliases andadditionalFields. The keys, aliases andadditionalFieldsof a join have one part, as the SQL adds their table, and those of a join of aQueryare not quoted, as they name its columns (a0_name);groupByalso accepts several columns separated by commas. An expression, or SQL given as a table name, is no longer accepted, and a quoted name has only letters, digits,_and$: join aQueryin place of a subquery - Breaking: The
opof a join must be one of=,!=,<>,<,<=,>and>=
New in 10.1.0 #
- Queries:
skipLockedmakes an update or a delete skip the rows that another transaction has locked, rather than wait for them, as for a queue that several workers take from at once. It needs a query that selects an id on MySQL 8 or MariaDB 10.6 or later, and an index on its conditions and order there - Queries:
orderByaccepts a quoted name, as a reserved word must be. Use the quote of the database: on MySQL and MariaDB, by default,"order"is a string, so sorting or grouping by it does nothing
Fixes in 10.1.0 #
- Queries: A query with no
fieldskeeps its joins, which were dropped without an error, so anINNER JOINfiltered nothing. It selectstable.*, only the columns of its own table - Queries:
isInandisNotInof a number, an enum or a string with no values areFALSEandTRUE, where they wereIN (), which is not valid SQL - Queries: An
offsetwithout alimithas aLIMITof the greatest value, as MySQL and MariaDB have noOFFSETwithout one, where it was a syntax error - Queries:
isInandisNotInof no values on a part of a date (year,month, ...) areFALSEandTRUE, where they were a syntax error - Queries: A self join is an
INNER JOINof the table by an alias, where it wasSELF JOIN, which is not valid SQL - Queries: A date predicate set directly is joined with
ANDto those of its parts (year,month, ...), which it discarded - Queries: An expression column is valid SQL in
getByKeys, and is left out of aRETURNING, where it may name a join that is not in scope, as the select around it computes it. ARETURNINGhas every column of the table, as that select may name any of them, in its order, joins or expressions, asselectleft out some that it named - Updates: The rows of a
limitare the first in the order oforderBy, which was ignored, so that other rows could be updated - Updates: The rows of a
limiton PostgreSQL are picked by table andctid, which is unique only within a table, where a partitioned or inherited table had a row of each table updated - Updates: The rows of a
limiton PostgreSQL, of an update or a delete, are locked and read once, as their subquery could otherwise run again and pick others, which would write more than the limit. A connection that waited for a row may still return none: useskipLockedfor a queue - Updates: The rows of a
limitor a join are picked with the joins of the query, so that anorderByor awhere.rawmay name a join, and anorderByan expression, an alias or a column that a join has too, as in a select - Updates: An insert or an update with a
RIGHT JOINor aFULL OUTER JOINreturns only the rows it wrote, as does a delete, where they returned others ofNULLcolumns, and alimitcounts only the rows of its table - Updates: An insert or an update on PostgreSQL with a join of its own table, as
selfJoin, reads the table, where it read only the rows it wrote, so that it returned no row. A join sees the table as it was before the statement - Updates: A
crossJoincounts as a join in an update and a delete, which an empty table leaves no row of: they updated or deleted every row that matchedwhere, and returned none. A select qualifies its columns with it, as they may be ambiguous - Updates: An update on MySQL of a query that selects no id throws a
StateErrorfor alimitor anoffset, as it could not tell the rows it selected, where alimitcould update other rows than those it returned, and anoffsetwas a syntax error - Updates: An update on MySQL with an id runs in a transaction, with the rows it finds locked, where it found, updated and selected them separately, so that two connections could pick the same rows, as of a queue, and a row could be overwritten after it stopped matching
where. It updates many rows in parts, as a database binds a limited number of parameters - Updates: An update on MySQL that sets the id returns the row by its new id, where it wrote the row and returned none. One of a query that selects no id locks the rows it selects, so that they are those it updates
- Updates: An update on MySQL of a query that selects no id returns the columns of its joins, where it dropped them, so that a relation that is joined came back empty, and a row with no
fields, where each was empty - Updates: An update or an insert with a
groupBythrows aStateError, where it was written and then failed or returned too few rows - Updates:
compileForUpdateleaves the values it is given as they are, is empty where it was a bareSETwith only a nullcreated_at, and throws anArgumentErrorfor a key that is not a plain column name, as a key ofMapQueryValueswas written into the SQL as given - Deletes: A
limitand anoffsetapply, in the order oforderBy, where they were a syntax error on PostgreSQL, and on MySQL with both. AnorderBywithout alimitorders the rows returned - Deletes: The rows returned are those deleted. A delete of a query with a join or a
limit, which it selects first, deletes the rows it selected by id, where anINNER JOINleft rows out of those returned but not of those deleted - Deletes: A delete of a query that selects an id deletes the rows it selected by id, where a query with relations and no
limitor join deleted by its conditions, and a row another connection added was deleted but not returned. It returns a row that a join repeats once, where acrossJoinreturned it once for each row of that table - Deletes: A delete that selects its rows first locks them, so that two connections cannot return the same rows, as of a queue. On PostgreSQL, a
RIGHT JOINor aFULL OUTER JOINcannot be locked - Deletes: A
groupBythrows aStateErrorwhere it was a syntax error. So does a delete of a query that selects no id with alimitor anoffseton MySQL, or on PostgreSQL with a join or a relation, or with a join other than aLEFT JOIN, as it could not tell the rows it selected - Inserts: An insert ignores the conditions,
limitandoffsetof its query, where its row was filtered out on PostgreSQL, and its row was not selected on MySQL - Executors: A predicate of a string that replaces another drops the values of that one, and an insert is not given those of the conditions it ignores, so that a query is given no unused value but one set by hand or of
where.raw. An executor whose driver rejects those must leave them out, asangel3_orm_postgres10.1.0 does - JSON: A property
asIntorasDoubleis compared as a number, wheregreaterThancompared text, so that10was less than5, andisBetweenandisInwere an error. A property that is no number matches no comparison - JSON: A property
asDateTimeis compared as a date, with a parameter of a valid name and the table name of the query, where its parameter was invalid - JSON: A property
asDateTimethat is no date, orasMaporasListthat is no JSON, matches no comparison, so that one such value does not fail the query for every row - JSON:
isNullandisNotNullof a propertyasInt,asDoubleorasDateTimecheck the value, so that a value of another type is not null - JSON: A property
asMaporasListhas predicates of its own, where they named the column twice, andisInof a propertyasStringhas a parameter of a valid name - JSON: A
'in the key of a property is escaped, where it was written into the SQL as given, so a key from a request could add SQL to a query - JSON: A key of a property with a backslash is an escape string, as the SQL around it was misread where a later
'followed: its parameters could keep the value of another query in a union, or be left out of an insert - Unions:
getandgetOneload the relations of the rows with those of the left query, asQuerydoes;parseRowsof aQueryBasegives them. - Unions: A union throws a
StateErrorwhere a value of its right query that it renamed is still named in its SQL, as it misread a string or a comment ofwhere.raw, or it is in a string, where it would have run with the value of its left query, without an error - Values:
mapToBoolreads the stringsfandfalse, in any case, as false - Values:
defaultDate, and themapToDateTimeof a null, is 1970-01-01 in UTC as documented, where it was in the local time zone
10.0.2 #
New in 10.0.2 #
- Logging:
debugMode, whether assertions are enabled, andlogValues, which logs the values of a query in debug mode only, for executors to log asQuerydoes
Fixes in 10.0.2 #
- Logging: The values of a query, which may be passwords or personal data, are logged in debug mode only, with assertions enabled (as with
dart testordart run --enable-asserts), where they were logged atFINEwhenever it was logged; those of an insert without an id and of an update on MySQL are logged too. Log messages are built only whenFINEis logged - Executors: An insert or a delete on PostgreSQL no longer gives the executor
returningFields, as its SQL has itsRETURNINGalready, in aWITHclause: an executor that added one, asPostgreSqlPoolExecutorofangel3_orm_postgres10.0.1 does, failed with a syntax error.QueryExecutor.querydocuments that its query is complete
10.0.1 #
Breaking changes in 10.0.1 #
- Breaking: A
DateTimein awhereclause with its time, such as oflessThan,equals,isBetweenorisIn, is bound as a parameter, so the executor sends it as it stores aDateTime, where it was written into the SQL as its wall-clock time, whatever its time zone. A localDateTimenow matches the rows written with it on PostgreSQL and withMariaDbExecutor, which store aDateTimeas UTC, and no longer matches rows they stored as local time before. AQueryExecutorof your own must accept aDateTimeparameter
Fixes in 10.0.1 #
- Queries: A
DateTimecomparison without its time (includeTime: false) compares the date of theDateTimeas given, as before - Queries:
isInandisNotInof aDateTimecolumn with no values areFALSEandTRUE, where they wereIN (), which is not valid SQL - Queries: A
Uniongives the right query's values names of their own where both queries use one, where the right query used the left one's value. It takes the values of its queries when it is compiled, so it also has those given after it was made
10.0.0 #
Breaking changes in 10.0.0 #
- Breaking:
get,update,deleteandinsertreturn records with the relationsloadRelationsloads, each with a query of its own after the records: a record is one row, so alimitoroffsetcounts records, andgetOnefetches one row - Breaking: On MySQL and MariaDB, an insert's
returningQueryselects the inserted row by the id given, or by@angel3_insert_id(insertIdParameter), which the executor binds to the driver's insert id, instead of the last row by id, which may be another connection's - Breaking:
Column.precisionandColumn.scaleareint?, andnullunless given (were 17 and 3). Anumericordecimalwithout them is unbounded on PostgreSQL
New in 10.0.0 #
replacePlaceholders, which swaps@nameplaceholders for a driver's (e.g.?)QueryValues.parameterNameOf, andColumn.defaultLength,defaultPrecisionanddefaultScaleQuery.loadRelations, which loads the relations of records that are not joined, such as a has-many, with a query each for all the records, andloadsRelations,getByKeys,pivotKeys,valueOfandjoinedRowfor it;JoinBuilder.queryandJoinBuilder.columnNameFor
Fixes in 10.0.0 #
- Joins: A query selects the columns of the joins of a query it joins, so a relation of a relation, such as a
@HasManynested in a@HasMany, is no longer dropped; a join that cannot be compiled selectsNULLs named as its columns, including those of its own joins, so the columns after it keep their place - Security:
StringSqlExpressionBuilder.likepasses its pattern as a parameter, where a pattern from user input allowed SQL injection;sanitizeis applied to the pattern - Parameters:
Query.reserveNamenever returns the same name twice, so two values of one column no longer overwrite each other (anupdatewith a condition and a new value on one column changed the wrong rows).replacePlaceholdersleaves@in string literals, quoted identifiers and@@variables - MySQL and MariaDB: An insert into a table without an id returns the values it inserted;
updateanddeleteselect their rows first, in a transaction, and return them.QueryValues.compileInsertSelectis deprecated update(): Returns the rows it updated even when their new values no longer match its conditions, and supportslimit()andoffset()on PostgreSQL- Conditions:
notWhereis joined withAND NOT, aWHEREno longer starts withAND/OR, and nested and JSON conditions are joined and qualified correctly. Date parts useEXTRACT;DateTimeisIn/isNotInquote the dates; adoubleis written as a plain number - Values:
mapToDoubleandmapToIntconvert numbers of the other type,BigInts and numeric strings, and throwFormatExceptionfor a value that cannot be converted getOne: Fetches one row (LIMIT 1) when the query has no joins and no limit of its own- Docs: The README tells how to install and use the package, and how to migrate from 9.x
9.1.1 #
- Fix analyzer warnings and errors
9.1.0 #
- Require Dart >= 3.13
9.0.0 #
- Require Dart >= 3.12
8.4.0 #
- Require Dart >= 3.8
- Updated
lintsto 6.0.0 - Updated dependencies to the latest release
8.3.2 #
- Updated
intlto 0.20.0
8.3.1 #
- Added support for string to bool conversion in the query results
8.3.0 #
- Set
createdAtandupdatedAtdefault to CURRENT_TIMESTAMP
8.2.0 #
- Require Dart >= 3.3
- Updated
lintsto 4.0.0
8.1.1 #
- Updated repository link
8.1.0 #
- Updated
lintsto 3.0.0 - Fixed linter warnings
8.0.0 #
- Require Dart >= 3.0
7.1.0 #
- Require Dart >= 2.18
7.0.1 #
- Reduced debugging verbosity
7.0.0 #
- Require Dart >= 2.17
6.1.0 #
- Fixed issue #68: Support for non-nullable type
- Added
defaultValueto@Columnannotation
6.0.1 #
- Added
mapToDateTime
6.0.0 #
- Require Dart >= 2.16
5.0.0 #
- Skipped release
4.1.0 #
- Added
MySQLDialectto handle MySQL database specific features - Updated
insertandupdatequery to support database without writable CTE
4.0.6 #
- Fixed multiple
orderByerror
4.0.5 #
- Added
where.raw() - Added
select(List fields)
4.0.4 #
- Changed default varchar size to 255
- Changed default primary key to serial
4.0.3 #
- Removed debugging messages
4.0.2 #
- Updated linter to
package:lints - Set
createdAtandupdatedAtto current datetime as default
4.0.1 #
- Fixed expressions parsing error
- Fixed json data type error
- Added debug logging to sql query execution
4.0.0 #
- Updated
Optionalpackage
4.0.0-beta.4 #
- Added
hasSizetoColumnType
4.0.0-beta.3 #
- Updated README
- Fixed NNBD issues
4.0.0-beta.2 #
- Fixed static analysis warning
4.0.0-beta.1 #
- Migrated to support Dart >= 2.12 NNBD
3.0.0 #
- Migrated to work with Dart >= 2.12 Non NNBD
2.1.0-beta.3 #
- Remove parentheses from
ASwhen renaming rawexpressions.
2.1.0-beta.2 #
- Add
expressionstoQuery, to support custom SQL expressions that are read as normal fields.
2.1.0-beta.1 #
- Calls to
leftJoin, etc. alias all fields in a child query, to preventambiguous column a0.iderrors.
2.1.0-beta #
- Split the formerly 600+ line
src/query.dartup into separate files. - BREAKING: Add a required
QueryExecutorargument totransactioncallbacks. - Make
JoinBuildertaketoas aString Function(). This will allow ORM queries to reference their joined subqueries. - Removed deprecated
Join,toSql,sanitizeExpression,isAscii. - Always put
ORDER BYbeforeLIMIT. and,or,notinQueryWhereinclude parentheses.- Add
joinTypetoRelationshipclass.
2.0.2 #
- Place
LIMITandOFFSETafterORDER BY.
2.0.1 #
- Apply
package:pedanticfixes. @PrimaryKey()no longer defaults toserial, allowing its type to be inferenced.
2.0.0 #
- Add
isNull,isNotNullgetters to builders.
2.0.0-dev.24 #
- Fix a bug that caused syntax errors on
ORDER BY. - Add
patterntolikeon string builder.sanitizeis optional. - Add
RawSql.
2.0.0-dev.23 #
- Add
@ManyToManyannotation, which builds many-to-many relations.
2.0.0-dev.22 #
compileInsertwill explicitly never emit a key not belonging to the associated query.
2.0.0-dev.21 #
- Add tableName to query
2.0.0-dev.20 #
- Join updates.
2.0.0-dev.19 #
- Implement cast-based
doublesupport. - Finish
ListSqlExpressionBuilder.
2.0.0-dev.18 #
- Add
ListSqlExpressionBuilder(still in development).
2.0.0-dev.17 #
- Add
EnumSqlExpressionBuilder.
2.0.0-dev.16 #
- Add
MapSqlExpressionBuilderfor JSON/JSONB support.
2.0.0-dev.15 #
- Remove
Column.defaultValue. - Deprecate
toSqlandsanitizeExpression. - Refactor builders so that strings are passed through
2.0.0-dev.14 #
- Remove obsolete
@belongsToMany.
2.0.0-dev.13 #
- Push for consistency with orm_gen @
2.0.0-dev.
2.0.0-dev.12 #
- Always apply
toSqlescapes.
2.0.0-dev.11 #
- Remove
limit(1)except ongetOne
2.0.0-dev.10 #
- Add
withFieldstocompile()
2.0.0-dev.9 #
- Permanent preamble fix
2.0.0-dev.8 #
- Escapes
2.0.0-dev.7 #
- Update
toSql - Add
isTrueandisFalse
2.0.0-dev.6 #
- Add
delete,insertandupdatemethods toQuery.
2.0.0-dev.4 #
- Add more querying methods.
- Add preamble to
Query.compile.
2.0.0-dev.3 #
- Brought back old-style query builder.
- Strong-mode updates, revised
Join.
2.0.0-dev.2 #
- Renamed
ORMtoOrm. Ormnow requires a database type.
2.0.0-dev.1 #
- Restored all old PostgreSQL-specific annotations. Rather than a smart runtime, having a codegen capable of building ORM's for multiple databases can potentially provide a very fast ORM for everyone.
2.0.0-dev #
- Removed PostgreSQL-specific functionality, so that the ORM can ultimately target all services.
- Created a better
Joinmodel. - Created a far better
Querymodel. - Removed
lib/server.dart
1.0.0-alpha+10 #
- Split into
angel_orm.dartandserver.dart. Prevents DDC failures.
1.0.0-alpha+7 #
- Added a
@belongsToManyannotation class. - Resolved ##20. The
PostgreSQLConnectionPoolkeeps track of which connections have been opened now.
1.0.0-alpha+6 #
DateTimeSqlExpressionBuilderwill no longer automatically insert quotation marks around names.
1.0.0-alpha+5 #
- Corrected a typo that was causing the aforementioned test failures.
==becomes=.
1.0.0-alpha+4 #
- Added a null-check in
lib/src/query.dart##L24to (hopefully) prevent it from crashing on Travis.
1.0.0-alpha+3 #
- Added
isIn,isNotIn,isBetween,isNotBetweentoSqlExpressionBuilderand its subclasses. - Added a dependency on
package:meta.