-
Notifications
You must be signed in to change notification settings - Fork 1
/
yaaiisDatabase.js
88 lines (73 loc) · 2.06 KB
/
yaaiisDatabase.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const SQLite = require('sqlite3').verbose();
// import SQLite from 'sqlite3';
const { Sequelize, Model, DataTypes } = require('sequelize');
// 'sqlite:yaaiis-database.sqlite'
const sequelize = new Sequelize('database', 'username', 'password', {
dialect: 'sqlite',
storage: './yaaiis-database.sqlite',
dialectOptions: {
// Your sqlite3 options here
// for instance, this is how you can configure the database opening mode:
mode: SQLite.OPEN_READWRITE | SQLite.OPEN_CREATE | SQLite.OPEN_FULLMUTEX,
},
});
const Image = sequelize.define('Image',
{
hash: {
type:DataTypes.TEXT,
primaryKey: true
},
model: DataTypes.TEXT,
modelHash: DataTypes.TEXT,
sampler: DataTypes.TEXT,
prompt: DataTypes.TEXT,
mtime: DataTypes.DATE,
ctime: DataTypes.DATE,
generationMetadata: DataTypes.JSON,
paths: DataTypes.JSON,
stats: DataTypes.JSON,
});
const Tag = sequelize.define('Tag',
{
uuid: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true
},
name: {
type: DataTypes.TEXT,
allowNull: false,
unique: true
},
});
const ImageTag = sequelize.define('ImageTag',
{
uuid: {
type: DataTypes.UUID,
primaryKey: true
},
hash: {
type: DataTypes.TEXT,
primaryKey: true
},
});
Tag.belongsToMany(Image, {through:'ImageTag', foreignKey: "uuid",})
Image.belongsToMany(Tag, { through: 'ImageTag', foreignKey: "hash", });
const models = {Image, Tag, ImageTag};
let _me;
const yaaiisDatabase = {
get : async () => {
if (_me) return _me;
try {
await Image.sync();
await Tag.sync();
await sequelize.sync();
_me = models;
_me.get = this.get;
return _me;
} catch (e) {
console.error(e);
}
}
}
module.exports = {yaaiisDatabase};