Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
Neos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Neos
Commits
c37bc844
Commit
c37bc844
authored
Jan 22, 2023
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add sqlite middleware
parent
9e2fb1f5
Pipeline
#19733
passed with stages
in 6 minutes and 19 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
0 deletions
+61
-0
src/middleware/sqlite.ts
src/middleware/sqlite.ts
+61
-0
No files found.
src/middleware/sqlite.ts
0 → 100644
View file @
c37bc844
/*
* Sqlite中间件
*
* 用于获取卡牌数据
*
* */
import
initSqlJs
,
{
Database
}
from
"
sql.js
"
;
export
enum
sqliteCmd
{
// 初始化
INIT
,
// 读取操作
SELECT
,
}
export
interface
sqliteAction
{
cmd
:
sqliteCmd
;
// 初始化DB需要业务方传入的数据
initInfo
?:
{
dbUrl
:
string
;
};
// 需要读取卡牌数据的ID
payload
?:
number
;
}
let
YGODB
:
Database
|
null
=
null
;
const
sqlPromise
=
initSqlJs
({
locateFile
:
(
file
)
=>
`/node_modules/sql.js/dist/
${
file
}
`
,
});
// FIXME: 应该有个返回值,告诉业务方本次请求的结果,比如初始化DB失败
export
default
async
function
(
action
:
sqliteAction
)
{
switch
(
action
.
cmd
)
{
case
sqliteCmd
.
INIT
:
{
const
info
=
action
.
initInfo
;
if
(
info
)
{
const
dataPromise
=
fetch
(
info
.
dbUrl
).
then
((
res
)
=>
res
.
arrayBuffer
());
// TODO: i18n
const
[
SQL
,
buffer
]
=
await
Promise
.
all
([
sqlPromise
,
dataPromise
]);
YGODB
=
new
SQL
.
Database
(
new
Uint8Array
(
buffer
));
}
break
;
}
case
sqliteCmd
.
SELECT
:
{
if
(
YGODB
)
{
// TDOO
}
else
{
console
.
warn
(
"
ygo db not init!
"
);
}
break
;
}
default
:
{
console
.
warn
(
`Unhandled sqlite command:
${
action
.
cmd
}
`
);
break
;
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment