Repository navigation
data-table v1.1.0
Minor Changes
-
Query builder reads and writes now convert values by column type, so rows have the same JavaScript shape on every adapter.
column.json()values are written withJSON.stringify(), including strings, and values compared witheq(),inList(), and the other value operators on ajsoncolumn are serialized the same way. Drivers can implement the new optionalDatabaseDriver.decodeValue(value, column)hook to convert values their database returns in a storage format;Databasecalls it for table query andreturningrows, whiledb.exec()results are returned unchanged. (#12337)Code that wrote already-serialized JSON text to a
json()column through the query builder now stores a JSON string instead of the encoded value. Pass the value itself:-await db.create(settings, { id: 1, data: JSON.stringify({ theme: 'dark' }) }) +await db.create(settings, { id: 1, data: { theme: 'dark' } })
Arrays interpolated into
sqlnow expand into a parenthesized list with one parameter per item, and an empty array throws. To bind an array as a single parameter, such as a PostgreSQL array, wrap it inrawSql:let byIds = sql`select * from users where id in ${['u_001', 'u_002']}` // select * from users where id in (?, ?) let byArray = sql`select * from users where id = any(${rawSql('?', [['u_001', 'u_002']])})`
-
Add shared SQL clause compilers to
@remix-run/data-table/sql-helpersso adapters no longer need their own copies of predicate and clause compilation.compilePredicate(),compileFromClause(),compileWhereClause(),compileHavingClause(),compileGroupByClause(),compileOrderByClause(),compileLimitOffsetClause(), andcompileReturningClause()take aSqlCompileContextthat supplies the dialect'squoteIdentifier(), abindValue()hook that records a value and returns its placeholder, and an optionalilikemode ('ilike'for native support,'lower-like'by default). (#12276)import { compileWhereClause } from 'remix/data-table/sql-helpers' let values: unknown[] = [] let where = compileWhereClause(operation.where, { quoteIdentifier: (name) => '"' + name.replace(/"/g, '""') + '"', bindValue(value) { values.push(value) return '$' + values.length }, })
The
JoinClause,JoinType, andReturningSelectiontypes used by these helpers are now exported from@remix-run/data-table.
Patch Changes
-
Nested
sqlcomposition now requires statements created bysqlorrawSqlfrom the same loaded copy of the package. Other statement objects are passed as parameter values. Directdb.exec()calls continue to accept structuralSqlStatementobjects. (#12332)Queries that compose hand-built, copied, deserialized, or separately loaded statements may now return different results or raise driver errors. Use the local
rawSqlhelper to create composable fragments:-let condition = { text: 'status = ?', values: ['active'] } +let condition = rawSql('status = ?', ['active']) let statement = sql`select * from users where ${condition}`