sequences

package
v1.2.84 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

README

SEQUENCE

create table

CREATE TABLE `sequence` (
  `name` varchar(255) NOT NULL,
  `value` bigint NOT NULL DEFAULT '0',
  `increment` int NOT NULL DEFAULT '1',
  PRIMARY KEY (`name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3;

create function

CREATE DEFINER=`root`@`%` FUNCTION `nextval`(sname varchar(255)) RETURNS bigint
    DETERMINISTIC
BEGIN
    declare next_val bigint(20);
    declare s int;
    set next_val = 0;
    select count(`name`) into s from `sequence` where `name` = sname;
    if (s = 0) then 
        insert into `sequence` values (sname, 0, 1);
    end if;
    update `sequence` set `value` = `value` + `increment` where `name` = sname;
    select `value` into `next_val` from `sequence` where `name` = sname limit 1;
RETURN next_val;
END

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Current

func Current(ctx context.Context, key string) (n int64, err error)

func Next

func Next(ctx context.Context, key string) (n int64, err error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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