Git Product home page Git Product logo

Comments (4)

dngferreira avatar dngferreira commented on September 26, 2024 1

After some testing found out I was using a database that was not clean. The columns were of the wrong type.
Thanks for the help

from drift.

simolus3 avatar simolus3 commented on September 26, 2024

This seems to work for me:

import 'dart:convert';

import 'package:drift/drift.dart';
import 'package:drift/native.dart';

part 'repro.g.dart';

class Messages extends Table {
  BlobColumn get id => blob()();

  TextColumn get msg => text()();

  @override
  Set<Column<Object>>? get primaryKey => {id};
}

@DriftDatabase(tables: [Messages])
class Database extends _$Database {
  Database(super.e);

  @override
  int get schemaVersion => 1;
}

void main() async {
  final db = Database(NativeDatabase.memory());

  final id = utf8.encode('test');
  print(await db
      .into(db.messages)
      .insertReturning(MessagesCompanion.insert(id: id, msg: 'initial')));

  await (db.update(db.messages)..where((tbl) => tbl.id.equals(id)))
      .write(MessagesCompanion(msg: Value('hello')));

  print(await db.messages.all().get());
}

Uint8Lists don't compare with operator= in Dart, but it should work in the SQL generated by drift.

from drift.

dngferreira avatar dngferreira commented on September 26, 2024

I'm using drift files to define the database model, could it be related to it?

from drift.

simolus3 avatar simolus3 commented on September 26, 2024

Good point, but it also works for me with

-- test.drift
CREATE TABLE messages (
    id BLOB NOT NULL PRIMARY KEY,
    msg TEXT NOT NULL);
import 'dart:convert';

import 'package:drift/drift.dart';
import 'package:drift/native.dart';

part 'repro.g.dart';

@DriftDatabase(include: {'test.drift'})
class Database extends _$Database {
  Database(super.e);

  @override
  int get schemaVersion => 1;
}

void main() async {
  final db = Database(NativeDatabase.memory());

  final id = utf8.encode('test');
  print(await db
      .into(db.messages)
      .insertReturning(MessagesCompanion.insert(id: id, msg: 'initial')));

  await (db.update(db.messages)..where((tbl) => tbl.id.equals(id)))
      .write(MessagesCompanion(msg: Value('hello')));

  print(await db.messages.all().get());
}

Does that work for you? I wonder if row.id in your original snippet may have an unintended value due to some other bug.

from drift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.