o2o2types/

directory
v0.0.0-...-fc31239 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2023 License: Apache-2.0

README

User-Card O2O Relation Example

An example for a O2O relation between a User and Card.
In the example, a User can have only one card, and a card must have exactly one owner (required edge).

Generate Assets
go generate ./...
Run Examples
go test

set FOREIGN_KEY_CHECKS = 0;
drop table users;
drop table cards;
set FOREIGN_KEY_CHECKS = 1;

CREATE TABLE `users` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `age` bigint(20) NOT NULL,
  `name` varchar(255) COLLATE utf8mb4_bin NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin

CREATE TABLE `cards` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `expired` timestamp NOT NULL,
  `number` varchar(255) COLLATE utf8mb4_bin NOT NULL,
  `user_card` bigint(20) NOT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `user_card` (`user_card`),
  CONSTRAINT `cards_users_card` FOREIGN KEY (`user_card`) REFERENCES `users` (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin

Directories

Path Synopsis
ent

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL